fix: draggable regions exclusively on BrowserViews (#26145)

This commit is contained in:
Shelley Vohr 2020-10-27 14:28:43 -07:00 committed by GitHub
parent 760c4aeb3e
commit 7cdc42f43a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 139 additions and 68 deletions

View file

@ -0,0 +1,42 @@
// Copyright (c) 2020 Microsoft, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/ui/drag_util.h"
#include <memory>
#include "ui/gfx/skia_util.h"
namespace electron {
// Return a vector of non-draggable regions that fill a window of size
// |width| by |height|, but leave gaps where the window should be draggable.
std::vector<gfx::Rect> CalculateNonDraggableRegions(
std::unique_ptr<SkRegion> draggable,
int width,
int height) {
std::vector<gfx::Rect> result;
SkRegion non_draggable;
non_draggable.op({0, 0, width, height}, SkRegion::kUnion_Op);
non_draggable.op(*draggable, SkRegion::kDifference_Op);
for (SkRegion::Iterator it(non_draggable); !it.done(); it.next()) {
result.push_back(gfx::SkIRectToRect(it.rect()));
}
return result;
}
// Convert draggable regions in raw format to SkRegion format.
std::unique_ptr<SkRegion> DraggableRegionsToSkRegion(
const std::vector<mojom::DraggableRegionPtr>& regions) {
auto sk_region = std::make_unique<SkRegion>();
for (const auto& region : regions) {
sk_region->op(
{region->bounds.x(), region->bounds.y(), region->bounds.right(),
region->bounds.bottom()},
region->draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
}
return sk_region;
}
} // namespace electron

View file

@ -5,8 +5,12 @@
#ifndef SHELL_BROWSER_UI_DRAG_UTIL_H_
#define SHELL_BROWSER_UI_DRAG_UTIL_H_
#include <memory>
#include <vector>
#include "shell/common/api/api.mojom.h"
#include "third_party/skia/include/core/SkRegion.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image.h"
namespace base {
@ -19,6 +23,15 @@ void DragFileItems(const std::vector<base::FilePath>& files,
const gfx::Image& icon,
gfx::NativeView view);
std::vector<gfx::Rect> CalculateNonDraggableRegions(
std::unique_ptr<SkRegion> draggable,
int width,
int height);
// Convert draggable regions in raw format to SkRegion format.
std::unique_ptr<SkRegion> DraggableRegionsToSkRegion(
const std::vector<mojom::DraggableRegionPtr>& regions);
} // namespace electron
#endif // SHELL_BROWSER_UI_DRAG_UTIL_H_