drag_util.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) 2020 Microsoft, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/browser/ui/drag_util.h"
  5. #include <memory>
  6. #include "ui/gfx/skia_util.h"
  7. namespace electron {
  8. // Return a vector of non-draggable regions that fill a window of size
  9. // |width| by |height|, but leave gaps where the window should be draggable.
  10. std::vector<gfx::Rect> CalculateNonDraggableRegions(
  11. std::unique_ptr<SkRegion> draggable,
  12. int width,
  13. int height) {
  14. std::vector<gfx::Rect> result;
  15. SkRegion non_draggable;
  16. non_draggable.op({0, 0, width, height}, SkRegion::kUnion_Op);
  17. non_draggable.op(*draggable, SkRegion::kDifference_Op);
  18. for (SkRegion::Iterator it(non_draggable); !it.done(); it.next()) {
  19. result.push_back(gfx::SkIRectToRect(it.rect()));
  20. }
  21. return result;
  22. }
  23. // Convert draggable regions in raw format to SkRegion format.
  24. std::unique_ptr<SkRegion> DraggableRegionsToSkRegion(
  25. const std::vector<mojom::DraggableRegionPtr>& regions) {
  26. auto sk_region = std::make_unique<SkRegion>();
  27. for (const auto& region : regions) {
  28. sk_region->op(
  29. SkIRect::MakeLTRB(region->bounds.x(), region->bounds.y(),
  30. region->bounds.right(), region->bounds.bottom()),
  31. region->draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
  32. }
  33. return sk_region;
  34. }
  35. } // namespace electron