refactor: mojofy draggable regions (#18536)
This commit is contained in:
parent
52c76d737a
commit
0b25176893
17 changed files with 59 additions and 91 deletions
|
@ -170,17 +170,6 @@ void BrowserWindow::OnRendererUnresponsive(content::RenderProcessHost*) {
|
|||
ScheduleUnresponsiveEvent(50);
|
||||
}
|
||||
|
||||
bool BrowserWindow::OnMessageReceived(const IPC::Message& message,
|
||||
content::RenderFrameHost* rfh) {
|
||||
bool handled = true;
|
||||
IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(BrowserWindow, message, rfh)
|
||||
IPC_MESSAGE_HANDLER(AtomFrameHostMsg_UpdateDraggableRegions,
|
||||
UpdateDraggableRegions)
|
||||
IPC_MESSAGE_UNHANDLED(handled = false)
|
||||
IPC_END_MESSAGE_MAP()
|
||||
return handled;
|
||||
}
|
||||
|
||||
void BrowserWindow::OnCloseContents() {
|
||||
// On some machines it may happen that the window gets destroyed for twice,
|
||||
// checking web_contents() can effectively guard against that.
|
||||
|
@ -216,6 +205,11 @@ void BrowserWindow::OnRendererResponsive() {
|
|||
Emit("responsive");
|
||||
}
|
||||
|
||||
void BrowserWindow::OnDraggableRegionsUpdated(
|
||||
const std::vector<mojom::DraggableRegionPtr>& regions) {
|
||||
UpdateDraggableRegions(regions);
|
||||
}
|
||||
|
||||
void BrowserWindow::RequestPreferredWidth(int* width) {
|
||||
*width = web_contents()->GetPreferredSize().width();
|
||||
}
|
||||
|
@ -276,7 +270,7 @@ void BrowserWindow::OnWindowFocus() {
|
|||
void BrowserWindow::OnWindowResize() {
|
||||
#if defined(OS_MACOSX)
|
||||
if (!draggable_regions_.empty())
|
||||
UpdateDraggableRegions(nullptr, draggable_regions_);
|
||||
UpdateDraggableRegions(draggable_regions_);
|
||||
#endif
|
||||
TopLevelWindow::OnWindowResize();
|
||||
}
|
||||
|
@ -314,28 +308,28 @@ void BrowserWindow::SetBrowserView(v8::Local<v8::Value> value) {
|
|||
TopLevelWindow::ResetBrowserViews();
|
||||
TopLevelWindow::AddBrowserView(value);
|
||||
#if defined(OS_MACOSX)
|
||||
UpdateDraggableRegions(nullptr, draggable_regions_);
|
||||
UpdateDraggableRegions(draggable_regions_);
|
||||
#endif
|
||||
}
|
||||
|
||||
void BrowserWindow::AddBrowserView(v8::Local<v8::Value> value) {
|
||||
TopLevelWindow::AddBrowserView(value);
|
||||
#if defined(OS_MACOSX)
|
||||
UpdateDraggableRegions(nullptr, draggable_regions_);
|
||||
UpdateDraggableRegions(draggable_regions_);
|
||||
#endif
|
||||
}
|
||||
|
||||
void BrowserWindow::RemoveBrowserView(v8::Local<v8::Value> value) {
|
||||
TopLevelWindow::RemoveBrowserView(value);
|
||||
#if defined(OS_MACOSX)
|
||||
UpdateDraggableRegions(nullptr, draggable_regions_);
|
||||
UpdateDraggableRegions(draggable_regions_);
|
||||
#endif
|
||||
}
|
||||
|
||||
void BrowserWindow::ResetBrowserViews() {
|
||||
TopLevelWindow::ResetBrowserViews();
|
||||
#if defined(OS_MACOSX)
|
||||
UpdateDraggableRegions(nullptr, draggable_regions_);
|
||||
UpdateDraggableRegions(draggable_regions_);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -377,13 +371,13 @@ v8::Local<v8::Value> BrowserWindow::GetWebContents(v8::Isolate* isolate) {
|
|||
|
||||
// Convert draggable regions in raw format to SkRegion format.
|
||||
std::unique_ptr<SkRegion> BrowserWindow::DraggableRegionsToSkRegion(
|
||||
const std::vector<DraggableRegion>& regions) {
|
||||
const std::vector<mojom::DraggableRegionPtr>& regions) {
|
||||
auto sk_region = std::make_unique<SkRegion>();
|
||||
for (const DraggableRegion& region : regions) {
|
||||
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);
|
||||
region->bounds.x(), region->bounds.y(), region->bounds.right(),
|
||||
region->bounds.bottom(),
|
||||
region->draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
|
||||
}
|
||||
return sk_region;
|
||||
}
|
||||
|
|
|
@ -51,12 +51,12 @@ class BrowserWindow : public TopLevelWindow,
|
|||
void DidFirstVisuallyNonEmptyPaint() override;
|
||||
void BeforeUnloadDialogCancelled() override;
|
||||
void OnRendererUnresponsive(content::RenderProcessHost*) override;
|
||||
bool OnMessageReceived(const IPC::Message& message,
|
||||
content::RenderFrameHost* rfh) override;
|
||||
|
||||
// ExtendedWebContentsObserver:
|
||||
void OnCloseContents() override;
|
||||
void OnRendererResponsive() override;
|
||||
void OnDraggableRegionsUpdated(
|
||||
const std::vector<mojom::DraggableRegionPtr>& regions) override;
|
||||
|
||||
// NativeWindowObserver:
|
||||
void RequestPreferredWidth(int* width) override;
|
||||
|
@ -91,12 +91,12 @@ class BrowserWindow : public TopLevelWindow,
|
|||
// Helpers.
|
||||
|
||||
// Called when the window needs to update its draggable region.
|
||||
void UpdateDraggableRegions(content::RenderFrameHost* rfh,
|
||||
const std::vector<DraggableRegion>& regions);
|
||||
void UpdateDraggableRegions(
|
||||
const std::vector<mojom::DraggableRegionPtr>& regions);
|
||||
|
||||
// Convert draggable regions in raw format to SkRegion format.
|
||||
std::unique_ptr<SkRegion> DraggableRegionsToSkRegion(
|
||||
const std::vector<DraggableRegion>& regions);
|
||||
const std::vector<mojom::DraggableRegionPtr>& regions);
|
||||
|
||||
// Schedule a notification unresponsive event.
|
||||
void ScheduleUnresponsiveEvent(int ms);
|
||||
|
@ -112,7 +112,7 @@ class BrowserWindow : public TopLevelWindow,
|
|||
base::CancelableClosure window_unresponsive_closure_;
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
std::vector<DraggableRegion> draggable_regions_;
|
||||
std::vector<mojom::DraggableRegionPtr> draggable_regions_;
|
||||
#endif
|
||||
|
||||
v8::Global<v8::Value> web_contents_;
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include "atom/browser/native_browser_view.h"
|
||||
#include "atom/browser/native_window_mac.h"
|
||||
#include "atom/browser/ui/inspectable_web_contents_view.h"
|
||||
#include "atom/common/draggable_region.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
|
||||
@interface NSView (WebContentsView)
|
||||
|
@ -76,8 +75,7 @@ void BrowserWindow::OverrideNSWindowContentView(InspectableWebContents* iwc) {
|
|||
}
|
||||
|
||||
void BrowserWindow::UpdateDraggableRegions(
|
||||
content::RenderFrameHost* rfh,
|
||||
const std::vector<DraggableRegion>& regions) {
|
||||
const std::vector<mojom::DraggableRegionPtr>& regions) {
|
||||
if (window_->has_frame())
|
||||
return;
|
||||
|
||||
|
@ -103,7 +101,9 @@ void BrowserWindow::UpdateDraggableRegions(
|
|||
|
||||
// Draggable regions is implemented by having the whole web view draggable
|
||||
// (mouseDownCanMoveWindow) and overlaying regions that are not draggable.
|
||||
draggable_regions_ = regions;
|
||||
draggable_regions_.clear();
|
||||
for (const auto& r : regions)
|
||||
draggable_regions_.push_back(r.Clone());
|
||||
std::vector<gfx::Rect> drag_exclude_rects;
|
||||
if (regions.empty()) {
|
||||
drag_exclude_rects.push_back(gfx::Rect(0, 0, webViewWidth, webViewHeight));
|
||||
|
@ -114,7 +114,7 @@ void BrowserWindow::UpdateDraggableRegions(
|
|||
|
||||
auto browser_views = window_->browser_views();
|
||||
for (NativeBrowserView* view : browser_views) {
|
||||
(view)->UpdateDraggableRegions(drag_exclude_rects);
|
||||
view->UpdateDraggableRegions(drag_exclude_rects);
|
||||
}
|
||||
|
||||
// Create and add a ControlRegionView for each region that needs to be
|
||||
|
|
|
@ -11,8 +11,7 @@ namespace atom {
|
|||
namespace api {
|
||||
|
||||
void BrowserWindow::UpdateDraggableRegions(
|
||||
content::RenderFrameHost* rfh,
|
||||
const std::vector<DraggableRegion>& regions) {
|
||||
const std::vector<mojom::DraggableRegionPtr>& regions) {
|
||||
if (window_->has_frame())
|
||||
return;
|
||||
static_cast<NativeWindowViews*>(window_.get())
|
||||
|
|
|
@ -964,6 +964,12 @@ void WebContents::MessageHost(const std::string& channel,
|
|||
base::nullopt, channel, std::move(arguments));
|
||||
}
|
||||
|
||||
void WebContents::UpdateDraggableRegions(
|
||||
std::vector<mojom::DraggableRegionPtr> regions) {
|
||||
for (ExtendedWebContentsObserver& observer : observers_)
|
||||
observer.OnDraggableRegionsUpdated(regions);
|
||||
}
|
||||
|
||||
void WebContents::RenderFrameDeleted(
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
// A RenderFrameHost can be destroyed before the related Mojo binding is
|
||||
|
|
|
@ -69,6 +69,8 @@ class ExtendedWebContentsObserver : public base::CheckedObserver {
|
|||
public:
|
||||
virtual void OnCloseContents() {}
|
||||
virtual void OnRendererResponsive() {}
|
||||
virtual void OnDraggableRegionsUpdated(
|
||||
const std::vector<mojom::DraggableRegionPtr>& regions) {}
|
||||
|
||||
protected:
|
||||
~ExtendedWebContentsObserver() override {}
|
||||
|
@ -505,6 +507,8 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
|||
const std::string& channel,
|
||||
base::Value arguments) override;
|
||||
void MessageHost(const std::string& channel, base::Value arguments) override;
|
||||
void UpdateDraggableRegions(
|
||||
std::vector<mojom::DraggableRegionPtr> regions) override;
|
||||
|
||||
// Called when we receive a CursorChange message from chromium.
|
||||
void OnCursorChange(const content::WebCursor& cursor);
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/draggable_region.h"
|
||||
#include "base/macros.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include <vector>
|
||||
|
||||
#include "atom/browser/native_browser_view.h"
|
||||
#include "atom/common/draggable_region.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
|
||||
namespace atom {
|
||||
|
|
|
@ -44,8 +44,6 @@ namespace atom {
|
|||
class AtomMenuModel;
|
||||
class NativeBrowserView;
|
||||
|
||||
struct DraggableRegion;
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
typedef NSView* NativeWindowHandle;
|
||||
#else
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "atom/browser/web_view_manager.h"
|
||||
#include "atom/browser/window_list.h"
|
||||
#include "atom/common/atom_constants.h"
|
||||
#include "atom/common/draggable_region.h"
|
||||
#include "atom/common/native_mate_converters/image_converter.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
|
|
|
@ -7,5 +7,6 @@ mojom("mojo") {
|
|||
|
||||
public_deps = [
|
||||
"//mojo/public/mojom/base",
|
||||
"//ui/gfx/geometry/mojo",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
module atom.mojom;
|
||||
|
||||
import "mojo/public/mojom/base/values.mojom";
|
||||
import "ui/gfx/geometry/mojo/geometry.mojom";
|
||||
|
||||
interface ElectronRenderer {
|
||||
Message(
|
||||
|
@ -13,6 +14,11 @@ interface ElectronRenderer {
|
|||
TakeHeapSnapshot(handle file) => (bool success);
|
||||
};
|
||||
|
||||
struct DraggableRegion {
|
||||
bool draggable;
|
||||
gfx.mojom.Rect bounds;
|
||||
};
|
||||
|
||||
interface ElectronBrowser {
|
||||
// Emits an event on |channel| from the ipcMain JavaScript object in the main
|
||||
// process.
|
||||
|
@ -50,4 +56,7 @@ interface ElectronBrowser {
|
|||
MessageHost(
|
||||
string channel,
|
||||
mojo_base.mojom.ListValue arguments);
|
||||
|
||||
UpdateDraggableRegions(
|
||||
array<DraggableRegion> regions);
|
||||
};
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
// Multiply-included file, no traditional include guard.
|
||||
|
||||
#include "atom/common/draggable_region.h"
|
||||
#include "base/strings/string16.h"
|
||||
#include "base/values.h"
|
||||
#include "content/public/common/common_param_traits.h"
|
||||
|
@ -20,11 +19,6 @@
|
|||
|
||||
#define IPC_MESSAGE_START ElectronMsgStart
|
||||
|
||||
IPC_STRUCT_TRAITS_BEGIN(atom::DraggableRegion)
|
||||
IPC_STRUCT_TRAITS_MEMBER(draggable)
|
||||
IPC_STRUCT_TRAITS_MEMBER(bounds)
|
||||
IPC_STRUCT_TRAITS_END()
|
||||
|
||||
IPC_MESSAGE_ROUTED3(AtomAutofillFrameHostMsg_ShowPopup,
|
||||
gfx::RectF /* bounds */,
|
||||
std::vector<base::string16> /* values */,
|
||||
|
@ -35,10 +29,6 @@ IPC_MESSAGE_ROUTED0(AtomAutofillFrameHostMsg_HidePopup)
|
|||
IPC_MESSAGE_ROUTED1(AtomAutofillFrameMsg_AcceptSuggestion,
|
||||
base::string16 /* suggestion */)
|
||||
|
||||
// Sent by the renderer when the draggable regions are updated.
|
||||
IPC_MESSAGE_ROUTED1(AtomFrameHostMsg_UpdateDraggableRegions,
|
||||
std::vector<atom::DraggableRegion> /* regions */)
|
||||
|
||||
// Update renderer process preferences.
|
||||
IPC_MESSAGE_CONTROL1(AtomMsg_UpdatePreferences, base::ListValue)
|
||||
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/common/draggable_region.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
DraggableRegion::DraggableRegion() : draggable(false) {}
|
||||
|
||||
} // namespace atom
|
|
@ -1,21 +0,0 @@
|
|||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_COMMON_DRAGGABLE_REGION_H_
|
||||
#define ATOM_COMMON_DRAGGABLE_REGION_H_
|
||||
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
struct DraggableRegion {
|
||||
bool draggable;
|
||||
gfx::Rect bounds;
|
||||
|
||||
DraggableRegion();
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_COMMON_DRAGGABLE_REGION_H_
|
|
@ -5,6 +5,7 @@
|
|||
#include "atom/renderer/atom_render_frame_observer.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "atom/common/api/api_messages.h"
|
||||
|
@ -19,11 +20,10 @@
|
|||
#include "content/public/renderer/render_view.h"
|
||||
#include "electron/atom/common/api/api.mojom.h"
|
||||
#include "ipc/ipc_message_macros.h"
|
||||
#include "mojo/public/cpp/bindings/associated_binding.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "net/base/net_module.h"
|
||||
#include "net/grit/net_resources.h"
|
||||
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
|
||||
#include "services/service_manager/public/cpp/interface_provider.h"
|
||||
#include "third_party/blink/public/platform/web_isolated_world_info.h"
|
||||
#include "third_party/blink/public/web/blink.h"
|
||||
#include "third_party/blink/public/web/web_document.h"
|
||||
|
@ -95,16 +95,20 @@ void AtomRenderFrameObserver::DidCreateScriptContext(
|
|||
void AtomRenderFrameObserver::DraggableRegionsChanged() {
|
||||
blink::WebVector<blink::WebDraggableRegion> webregions =
|
||||
render_frame_->GetWebFrame()->GetDocument().DraggableRegions();
|
||||
std::vector<DraggableRegion> regions;
|
||||
std::vector<mojom::DraggableRegionPtr> regions;
|
||||
for (auto& webregion : webregions) {
|
||||
DraggableRegion region;
|
||||
auto region = mojom::DraggableRegion::New();
|
||||
render_frame_->GetRenderView()->ConvertViewportToWindowViaWidget(
|
||||
&webregion.bounds);
|
||||
region.bounds = webregion.bounds;
|
||||
region.draggable = webregion.draggable;
|
||||
regions.push_back(region);
|
||||
region->bounds = webregion.bounds;
|
||||
region->draggable = webregion.draggable;
|
||||
regions.push_back(std::move(region));
|
||||
}
|
||||
Send(new AtomFrameHostMsg_UpdateDraggableRegions(routing_id(), regions));
|
||||
|
||||
mojom::ElectronBrowserPtr browser_ptr;
|
||||
render_frame_->GetRemoteInterfaces()->GetInterface(
|
||||
mojo::MakeRequest(&browser_ptr));
|
||||
browser_ptr->UpdateDraggableRegions(std::move(regions));
|
||||
}
|
||||
|
||||
void AtomRenderFrameObserver::WillReleaseScriptContext(
|
||||
|
|
|
@ -512,8 +512,6 @@ filenames = {
|
|||
"atom/common/crash_reporter/win/crash_service.h",
|
||||
"atom/common/crash_reporter/win/crash_service_main.cc",
|
||||
"atom/common/crash_reporter/win/crash_service_main.h",
|
||||
"atom/common/draggable_region.cc",
|
||||
"atom/common/draggable_region.h",
|
||||
"atom/common/gin_util.h",
|
||||
"atom/common/heap_snapshot.cc",
|
||||
"atom/common/heap_snapshot.h",
|
||||
|
|
Loading…
Reference in a new issue