UpdateDraggableRegionViews is redundant
This commit is contained in:
parent
6650a06339
commit
384b03d49b
2 changed files with 94 additions and 110 deletions
|
@ -119,6 +119,12 @@ class NativeWindowMac : public NativeWindow,
|
||||||
void RefreshTouchBarItem(const std::string& item_id) override;
|
void RefreshTouchBarItem(const std::string& item_id) override;
|
||||||
void SetEscapeTouchBarItem(const mate::PersistentDictionary& item) override;
|
void SetEscapeTouchBarItem(const mate::PersistentDictionary& item) override;
|
||||||
|
|
||||||
|
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) const;
|
||||||
|
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const;
|
||||||
|
void UpdateDraggableRegions(
|
||||||
|
content::RenderFrameHost* rfh,
|
||||||
|
const std::vector<DraggableRegion>& regions) override;
|
||||||
|
|
||||||
// content::RenderWidgetHost::InputEventObserver:
|
// content::RenderWidgetHost::InputEventObserver:
|
||||||
void OnInputEvent(const blink::WebInputEvent& event) override;
|
void OnInputEvent(const blink::WebInputEvent& event) override;
|
||||||
|
|
||||||
|
@ -126,11 +132,6 @@ class NativeWindowMac : public NativeWindow,
|
||||||
void RenderViewHostChanged(content::RenderViewHost* old_host,
|
void RenderViewHostChanged(content::RenderViewHost* old_host,
|
||||||
content::RenderViewHost* new_host) override;
|
content::RenderViewHost* new_host) override;
|
||||||
|
|
||||||
// Refresh the DraggableRegion views.
|
|
||||||
void UpdateDraggableRegionViews() {
|
|
||||||
UpdateDraggableRegionViews(draggable_regions_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the attribute of NSWindow while work around a bug of zoom button.
|
// Set the attribute of NSWindow while work around a bug of zoom button.
|
||||||
void SetStyleMask(bool on, NSUInteger flag);
|
void SetStyleMask(bool on, NSUInteger flag);
|
||||||
void SetCollectionBehavior(bool on, NSUInteger flag);
|
void SetCollectionBehavior(bool on, NSUInteger flag);
|
||||||
|
@ -144,10 +145,11 @@ class NativeWindowMac : public NativeWindow,
|
||||||
TitleBarStyle title_bar_style() const { return title_bar_style_; }
|
TitleBarStyle title_bar_style() const { return title_bar_style_; }
|
||||||
|
|
||||||
bool zoom_to_page_width() const { return zoom_to_page_width_; }
|
bool zoom_to_page_width() const { return zoom_to_page_width_; }
|
||||||
|
|
||||||
bool fullscreen_window_title() const { return fullscreen_window_title_; }
|
bool fullscreen_window_title() const { return fullscreen_window_title_; }
|
||||||
|
|
||||||
bool simple_fullscreen() const { return always_simple_fullscreen_; }
|
bool simple_fullscreen() const { return always_simple_fullscreen_; }
|
||||||
|
const std::vector<DraggableRegion>& draggable_regions() const {
|
||||||
|
return draggable_regions_;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Return a vector of non-draggable regions that fill a window of size
|
// Return a vector of non-draggable regions that fill a window of size
|
||||||
|
@ -156,23 +158,12 @@ class NativeWindowMac : public NativeWindow,
|
||||||
const std::vector<DraggableRegion>& regions, int width, int height);
|
const std::vector<DraggableRegion>& regions, int width, int height);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// NativeWindow:
|
|
||||||
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) const;
|
|
||||||
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const;
|
|
||||||
void UpdateDraggableRegions(
|
|
||||||
content::RenderFrameHost* rfh,
|
|
||||||
const std::vector<DraggableRegion>& regions) override;
|
|
||||||
|
|
||||||
void InternalSetParentWindow(NativeWindow* parent, bool attach);
|
void InternalSetParentWindow(NativeWindow* parent, bool attach);
|
||||||
void ShowWindowButton(NSWindowButton button);
|
void ShowWindowButton(NSWindowButton button);
|
||||||
|
|
||||||
void InstallView();
|
void InstallView();
|
||||||
void UninstallView();
|
void UninstallView();
|
||||||
|
|
||||||
// Install the drag view, which will cover the whole window and decides
|
|
||||||
// whether we can drag.
|
|
||||||
void UpdateDraggableRegionViews(const std::vector<DraggableRegion>& regions);
|
|
||||||
|
|
||||||
void RegisterInputEventObserver(content::RenderViewHost* host);
|
void RegisterInputEventObserver(content::RenderViewHost* host);
|
||||||
void UnregisterInputEventObserver(content::RenderViewHost* host);
|
void UnregisterInputEventObserver(content::RenderViewHost* host);
|
||||||
|
|
||||||
|
|
|
@ -296,7 +296,7 @@ bool ScopedDisableResize::disable_resize_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidResize:(NSNotification*)notification {
|
- (void)windowDidResize:(NSNotification*)notification {
|
||||||
shell_->UpdateDraggableRegionViews();
|
shell_->UpdateDraggableRegions(nullptr, shell_->draggable_regions());
|
||||||
shell_->NotifyWindowResize();
|
shell_->NotifyWindowResize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1789,6 +1789,90 @@ void NativeWindowMac::SetEscapeTouchBarItem(const mate::PersistentDictionary& it
|
||||||
[window_ setEscapeTouchBarItem:item];
|
[window_ setEscapeTouchBarItem:item];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gfx::Rect NativeWindowMac::ContentBoundsToWindowBounds(
|
||||||
|
const gfx::Rect& bounds) const {
|
||||||
|
if (has_frame()) {
|
||||||
|
gfx::Rect window_bounds(
|
||||||
|
[window_ frameRectForContentRect:bounds.ToCGRect()]);
|
||||||
|
int frame_height = window_bounds.height() - bounds.height();
|
||||||
|
window_bounds.set_y(window_bounds.y() - frame_height);
|
||||||
|
return window_bounds;
|
||||||
|
} else {
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx::Rect NativeWindowMac::WindowBoundsToContentBounds(
|
||||||
|
const gfx::Rect& bounds) const {
|
||||||
|
if (has_frame()) {
|
||||||
|
gfx::Rect content_bounds(
|
||||||
|
[window_ contentRectForFrameRect:bounds.ToCGRect()]);
|
||||||
|
int frame_height = bounds.height() - content_bounds.height();
|
||||||
|
content_bounds.set_y(content_bounds.y() + frame_height);
|
||||||
|
return content_bounds;
|
||||||
|
} else {
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NativeWindowMac::UpdateDraggableRegions(
|
||||||
|
content::RenderFrameHost* rfh,
|
||||||
|
const std::vector<DraggableRegion>& regions) {
|
||||||
|
if (has_frame())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// All ControlRegionViews should be added as children of the WebContentsView,
|
||||||
|
// because WebContentsView will be removed and re-added when entering and
|
||||||
|
// leaving fullscreen mode.
|
||||||
|
NSView* webView = web_contents()->GetNativeView();
|
||||||
|
NSInteger webViewWidth = NSWidth([webView bounds]);
|
||||||
|
NSInteger webViewHeight = NSHeight([webView bounds]);
|
||||||
|
|
||||||
|
if ([webView respondsToSelector:@selector(setMouseDownCanMoveWindow:)]) {
|
||||||
|
[webView setMouseDownCanMoveWindow:YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove all ControlRegionViews that are added last time.
|
||||||
|
// Note that [webView subviews] returns the view's mutable internal array and
|
||||||
|
// it should be copied to avoid mutating the original array while enumerating
|
||||||
|
// it.
|
||||||
|
base::scoped_nsobject<NSArray> subviews([[webView subviews] copy]);
|
||||||
|
for (NSView* subview in subviews.get())
|
||||||
|
if ([subview isKindOfClass:[ControlRegionView class]])
|
||||||
|
[subview removeFromSuperview];
|
||||||
|
|
||||||
|
// Draggable regions is implemented by having the whole web view draggable
|
||||||
|
// (mouseDownCanMoveWindow) and overlaying regions that are not draggable.
|
||||||
|
draggable_regions_ = regions;
|
||||||
|
std::vector<gfx::Rect> system_drag_exclude_areas =
|
||||||
|
CalculateNonDraggableRegions(regions, webViewWidth, webViewHeight);
|
||||||
|
|
||||||
|
if (browser_view_)
|
||||||
|
browser_view_->UpdateDraggableRegions(system_drag_exclude_areas);
|
||||||
|
|
||||||
|
// Create and add a ControlRegionView for each region that needs to be
|
||||||
|
// excluded from the dragging.
|
||||||
|
for (std::vector<gfx::Rect>::const_iterator iter =
|
||||||
|
system_drag_exclude_areas.begin();
|
||||||
|
iter != system_drag_exclude_areas.end();
|
||||||
|
++iter) {
|
||||||
|
base::scoped_nsobject<NSView> controlRegion(
|
||||||
|
[[ControlRegionView alloc] initWithFrame:NSZeroRect]);
|
||||||
|
[controlRegion setFrame:NSMakeRect(iter->x(),
|
||||||
|
webViewHeight - iter->bottom(),
|
||||||
|
iter->width(),
|
||||||
|
iter->height())];
|
||||||
|
[webView addSubview:controlRegion];
|
||||||
|
}
|
||||||
|
|
||||||
|
// AppKit will not update its cache of mouseDownCanMoveWindow unless something
|
||||||
|
// changes. Previously we tried adding an NSView and removing it, but for some
|
||||||
|
// reason it required reposting the mouse-down event, and didn't always work.
|
||||||
|
// Calling the below seems to be an effective solution.
|
||||||
|
[window_ setMovableByWindowBackground:NO];
|
||||||
|
[window_ setMovableByWindowBackground:YES];
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowMac::OnInputEvent(const blink::WebInputEvent& event) {
|
void NativeWindowMac::OnInputEvent(const blink::WebInputEvent& event) {
|
||||||
switch (event.GetType()) {
|
switch (event.GetType()) {
|
||||||
case blink::WebInputEvent::kGestureScrollBegin:
|
case blink::WebInputEvent::kGestureScrollBegin:
|
||||||
|
@ -1825,40 +1909,6 @@ std::vector<gfx::Rect> NativeWindowMac::CalculateNonDraggableRegions(
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::Rect NativeWindowMac::ContentBoundsToWindowBounds(
|
|
||||||
const gfx::Rect& bounds) const {
|
|
||||||
if (has_frame()) {
|
|
||||||
gfx::Rect window_bounds(
|
|
||||||
[window_ frameRectForContentRect:bounds.ToCGRect()]);
|
|
||||||
int frame_height = window_bounds.height() - bounds.height();
|
|
||||||
window_bounds.set_y(window_bounds.y() - frame_height);
|
|
||||||
return window_bounds;
|
|
||||||
} else {
|
|
||||||
return bounds;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gfx::Rect NativeWindowMac::WindowBoundsToContentBounds(
|
|
||||||
const gfx::Rect& bounds) const {
|
|
||||||
if (has_frame()) {
|
|
||||||
gfx::Rect content_bounds(
|
|
||||||
[window_ contentRectForFrameRect:bounds.ToCGRect()]);
|
|
||||||
int frame_height = bounds.height() - content_bounds.height();
|
|
||||||
content_bounds.set_y(content_bounds.y() + frame_height);
|
|
||||||
return content_bounds;
|
|
||||||
} else {
|
|
||||||
return bounds;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindowMac::UpdateDraggableRegions(
|
|
||||||
content::RenderFrameHost* rfh,
|
|
||||||
const std::vector<DraggableRegion>& regions) {
|
|
||||||
NativeWindow::UpdateDraggableRegions(rfh, regions);
|
|
||||||
draggable_regions_ = regions;
|
|
||||||
UpdateDraggableRegionViews(regions);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindowMac::InternalSetParentWindow(NativeWindow* parent, bool attach) {
|
void NativeWindowMac::InternalSetParentWindow(NativeWindow* parent, bool attach) {
|
||||||
if (is_modal())
|
if (is_modal())
|
||||||
return;
|
return;
|
||||||
|
@ -1944,63 +1994,6 @@ void NativeWindowMac::UninstallView() {
|
||||||
[view removeFromSuperview];
|
[view removeFromSuperview];
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::UpdateDraggableRegionViews(
|
|
||||||
const std::vector<DraggableRegion>& regions) {
|
|
||||||
if (has_frame())
|
|
||||||
return;
|
|
||||||
|
|
||||||
// All ControlRegionViews should be added as children of the WebContentsView,
|
|
||||||
// because WebContentsView will be removed and re-added when entering and
|
|
||||||
// leaving fullscreen mode.
|
|
||||||
NSView* webView = web_contents()->GetNativeView();
|
|
||||||
NSInteger webViewWidth = NSWidth([webView bounds]);
|
|
||||||
NSInteger webViewHeight = NSHeight([webView bounds]);
|
|
||||||
|
|
||||||
if ([webView respondsToSelector:@selector(setMouseDownCanMoveWindow:)]) {
|
|
||||||
[webView setMouseDownCanMoveWindow:YES];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove all ControlRegionViews that are added last time.
|
|
||||||
// Note that [webView subviews] returns the view's mutable internal array and
|
|
||||||
// it should be copied to avoid mutating the original array while enumerating
|
|
||||||
// it.
|
|
||||||
base::scoped_nsobject<NSArray> subviews([[webView subviews] copy]);
|
|
||||||
for (NSView* subview in subviews.get())
|
|
||||||
if ([subview isKindOfClass:[ControlRegionView class]])
|
|
||||||
[subview removeFromSuperview];
|
|
||||||
|
|
||||||
// Draggable regions is implemented by having the whole web view draggable
|
|
||||||
// (mouseDownCanMoveWindow) and overlaying regions that are not draggable.
|
|
||||||
std::vector<gfx::Rect> system_drag_exclude_areas =
|
|
||||||
CalculateNonDraggableRegions(regions, webViewWidth, webViewHeight);
|
|
||||||
|
|
||||||
if (browser_view_) {
|
|
||||||
browser_view_->UpdateDraggableRegions(system_drag_exclude_areas);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create and add a ControlRegionView for each region that needs to be
|
|
||||||
// excluded from the dragging.
|
|
||||||
for (std::vector<gfx::Rect>::const_iterator iter =
|
|
||||||
system_drag_exclude_areas.begin();
|
|
||||||
iter != system_drag_exclude_areas.end();
|
|
||||||
++iter) {
|
|
||||||
base::scoped_nsobject<NSView> controlRegion(
|
|
||||||
[[ControlRegionView alloc] initWithFrame:NSZeroRect]);
|
|
||||||
[controlRegion setFrame:NSMakeRect(iter->x(),
|
|
||||||
webViewHeight - iter->bottom(),
|
|
||||||
iter->width(),
|
|
||||||
iter->height())];
|
|
||||||
[webView addSubview:controlRegion];
|
|
||||||
}
|
|
||||||
|
|
||||||
// AppKit will not update its cache of mouseDownCanMoveWindow unless something
|
|
||||||
// changes. Previously we tried adding an NSView and removing it, but for some
|
|
||||||
// reason it required reposting the mouse-down event, and didn't always work.
|
|
||||||
// Calling the below seems to be an effective solution.
|
|
||||||
[window_ setMovableByWindowBackground:NO];
|
|
||||||
[window_ setMovableByWindowBackground:YES];
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindowMac::SetStyleMask(bool on, NSUInteger flag) {
|
void NativeWindowMac::SetStyleMask(bool on, NSUInteger flag) {
|
||||||
// Changing the styleMask of a frameless windows causes it to change size so
|
// Changing the styleMask of a frameless windows causes it to change size so
|
||||||
// we explicitly disable resizing while setting it.
|
// we explicitly disable resizing while setting it.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue