Commit 78a0d81f authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

RemoteMacViews: Push window size and display properties

The methods NativeWidgetMac::GetWindowBoundsInScreen,
GetClientAreaBoundsInScreen, and GetWorkAreaBoundsInScreen compute
their results by querying the underlying NSWindow.

When the NSWindow is a separate process, this won't be an option.
Instead, have the BridgedNativeWidget push these properties to the
BridgetNativeWidgetHost, from which the NativeWidgetMac may query them.

Also have the BridgedNativeWidget (in the app shim process) query the
display::Display for its NSWindow and send that to the
BridgetNativeWidgetHost (in the browser process). This can then be
used to update the device scale factor, vsync, and color space
properties of the compositor (at present these properties updated only
by attached RenderWidgetHostViewMacs).

Rename BridgedNativeWidgetHost::SetSize to SetViewSize, to indicate
that it is computed differently.

Remove BridgedNativeWidgetHost::SetCompositorSize as its functionality
can be rolled into the new function.

Bug: 859152
Change-Id: If00184c31f9c493ece4ea08ace11d0be3a866786
Reviewed-on: https://chromium-review.googlesource.com/1175428
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584308}
parent 7f48b354
...@@ -745,7 +745,7 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) { ...@@ -745,7 +745,7 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) {
[super setFrameSize:newSize]; [super setFrameSize:newSize];
if (!host_) if (!host_)
return; return;
host_->SetSize(gfx::Size(newSize.width, newSize.height)); host_->SetViewSize(gfx::Size(newSize.width, newSize.height));
} }
- (BOOL)isOpaque { - (BOOL)isOpaque {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ui/accelerated_widget_mac/ca_transaction_observer.h" #include "ui/accelerated_widget_mac/ca_transaction_observer.h"
#include "ui/accelerated_widget_mac/display_ca_layer_tree.h" #include "ui/accelerated_widget_mac/display_ca_layer_tree.h"
#include "ui/base/ime/text_input_client.h" #include "ui/base/ime/text_input_client.h"
#include "ui/display/display_observer.h"
#import "ui/views/cocoa/bridged_native_widget_owner.h" #import "ui/views/cocoa/bridged_native_widget_owner.h"
#import "ui/views/cocoa/cocoa_mouse_capture_delegate.h" #import "ui/views/cocoa/cocoa_mouse_capture_delegate.h"
#import "ui/views/cocoa/native_widget_mac_nswindow.h" #import "ui/views/cocoa/native_widget_mac_nswindow.h"
...@@ -62,6 +63,7 @@ class VIEWS_EXPORT BridgedNativeWidgetPublic { ...@@ -62,6 +63,7 @@ class VIEWS_EXPORT BridgedNativeWidgetPublic {
// NativeWidgetMac to the Cocoa window. Behaves a bit like an aura::Window. // NativeWidgetMac to the Cocoa window. Behaves a bit like an aura::Window.
class VIEWS_EXPORT BridgedNativeWidget class VIEWS_EXPORT BridgedNativeWidget
: public BridgedNativeWidgetPublic, : public BridgedNativeWidgetPublic,
public display::DisplayObserver,
public ui::CATransactionCoordinator::PreCommitObserver, public ui::CATransactionCoordinator::PreCommitObserver,
public CocoaMouseCaptureDelegate, public CocoaMouseCaptureDelegate,
public BridgedNativeWidgetOwner { public BridgedNativeWidgetOwner {
...@@ -230,6 +232,10 @@ class VIEWS_EXPORT BridgedNativeWidget ...@@ -230,6 +232,10 @@ class VIEWS_EXPORT BridgedNativeWidget
bool ShouldRunCustomAnimationFor( bool ShouldRunCustomAnimationFor(
Widget::VisibilityTransition transition) const; Widget::VisibilityTransition transition) const;
// display::DisplayObserver:
void OnDisplayMetricsChanged(const display::Display& display,
uint32_t metrics) override;
// ui::CATransactionCoordinator::PreCommitObserver: // ui::CATransactionCoordinator::PreCommitObserver:
bool ShouldWaitInPreCommit() override; bool ShouldWaitInPreCommit() override;
base::TimeDelta PreCommitTimeout() override; base::TimeDelta PreCommitTimeout() override;
...@@ -252,16 +258,16 @@ class VIEWS_EXPORT BridgedNativeWidget ...@@ -252,16 +258,16 @@ class VIEWS_EXPORT BridgedNativeWidget
// Notify descendants of a visibility change. // Notify descendants of a visibility change.
void NotifyVisibilityChangeDown(); void NotifyVisibilityChangeDown();
// Essentially NativeWidgetMac::GetClientAreaBoundsInScreen().size(), but no
// coordinate transformations are required from AppKit coordinates.
gfx::Size GetClientAreaSize() const;
// Installs the NSView for hosting the composited layer. // Installs the NSView for hosting the composited layer.
void AddCompositorSuperview(); void AddCompositorSuperview();
// Size the layer to match the client area bounds, taking into account display // Compute the window and content size, and forward them to |host_|. This will
// scale factor. // update widget and compositor size.
void UpdateCompositorSizeAndScale(); void UpdateWindowGeometry();
// Query the display properties of the monitor that |window_| is on, and
// forward them to |host_|.
void UpdateWindowDisplay();
// Show the window using -[NSApp beginSheet:..], modal for the parent window. // Show the window using -[NSApp beginSheet:..], modal for the parent window.
void ShowAsModalSheet(); void ShowAsModalSheet();
...@@ -302,8 +308,14 @@ class VIEWS_EXPORT BridgedNativeWidget ...@@ -302,8 +308,14 @@ class VIEWS_EXPORT BridgedNativeWidget
BridgedNativeWidgetOwner* parent_; // Weak. If non-null, owns this. BridgedNativeWidgetOwner* parent_; // Weak. If non-null, owns this.
std::vector<BridgedNativeWidget*> child_windows_; std::vector<BridgedNativeWidget*> child_windows_;
// The size of the most recently received compositor frame. Note that this // The size of the content area of the window most recently sent to |host_|
// may lag behind GetClientAreaSize. // (and its compositor).
gfx::Size content_dip_size_;
// The size of the frame most recently *received from* the compositor. Note
// that during resize (and showing new windows), this will lag behind
// |content_dip_size_|, which is the frame size most recently *sent to* the
// compositor.
gfx::Size compositor_frame_dip_size_; gfx::Size compositor_frame_dip_size_;
base::scoped_nsobject<NSView> compositor_superview_; base::scoped_nsobject<NSView> compositor_superview_;
std::unique_ptr<ui::DisplayCALayerTree> display_ca_layer_tree_; std::unique_ptr<ui::DisplayCALayerTree> display_ca_layer_tree_;
...@@ -313,13 +325,6 @@ class VIEWS_EXPORT BridgedNativeWidget ...@@ -313,13 +325,6 @@ class VIEWS_EXPORT BridgedNativeWidget
// has its own copy, but doesn't provide access to it). // has its own copy, but doesn't provide access to it).
gfx::Rect bounds_before_fullscreen_; gfx::Rect bounds_before_fullscreen_;
// Tracks the origin of the window (from the top-left of the screen) when it
// was last reported to toolkit-views. Needed to trigger move notifications
// associated with a window resize since AppKit won't send move notifications
// when the top-left point of the window moves vertically. The origin of the
// window in AppKit coordinates is not actually changing in this case.
gfx::Point last_window_frame_origin_;
// The transition types to animate when not relying on native NSWindow // The transition types to animate when not relying on native NSWindow
// animation behaviors. Bitmask of Widget::VisibilityTransition. // animation behaviors. Bitmask of Widget::VisibilityTransition.
int transitions_to_animate_ = Widget::ANIMATE_BOTH; int transitions_to_animate_ = Widget::ANIMATE_BOTH;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
#include "ui/base/layout.h" #include "ui/base/layout.h"
#include "ui/base/ui_base_switches.h" #include "ui/base/ui_base_switches.h"
#include "ui/display/screen.h"
#include "ui/gfx/geometry/dip_util.h" #include "ui/gfx/geometry/dip_util.h"
#import "ui/gfx/mac/coordinate_conversion.h" #import "ui/gfx/mac/coordinate_conversion.h"
#import "ui/gfx/mac/nswindow_frame_controls.h" #import "ui/gfx/mac/nswindow_frame_controls.h"
...@@ -120,10 +121,6 @@ using NSViewComparatorValue = __kindof NSView*; ...@@ -120,10 +121,6 @@ using NSViewComparatorValue = __kindof NSView*;
int kWindowPropertiesKey; int kWindowPropertiesKey;
float GetDeviceScaleFactorFromView(NSView* view) {
return ui::GetScaleFactorForNativeView(view);
}
// Returns true if bounds passed to window in SetBounds should be treated as // Returns true if bounds passed to window in SetBounds should be treated as
// though they are in screen coordinates. // though they are in screen coordinates.
bool PositionWindowInScreenCoordinates(views::Widget* widget, bool PositionWindowInScreenCoordinates(views::Widget* widget,
...@@ -717,28 +714,11 @@ void BridgedNativeWidget::ToggleDesiredFullscreenState(bool async) { ...@@ -717,28 +714,11 @@ void BridgedNativeWidget::ToggleDesiredFullscreenState(bool async) {
} }
void BridgedNativeWidget::OnSizeChanged() { void BridgedNativeWidget::OnSizeChanged() {
const gfx::Rect new_bounds = native_widget_mac_->GetWindowBoundsInScreen(); UpdateWindowGeometry();
if (new_bounds.origin() != last_window_frame_origin_) {
native_widget_mac_->GetWidget()->OnNativeWidgetMove();
last_window_frame_origin_ = new_bounds.origin();
}
// Note we can't use new_bounds.size(), since it includes the titlebar for the
// purposes of detecting a window move.
gfx::Size new_size = GetClientAreaSize();
native_widget_mac_->GetWidget()->OnNativeWidgetSizeChanged(new_size);
UpdateCompositorSizeAndScale();
} }
void BridgedNativeWidget::OnPositionChanged() { void BridgedNativeWidget::OnPositionChanged() {
// When a window grows vertically, the AppKit origin changes, but as far as UpdateWindowGeometry();
// tookit-views is concerned, the window hasn't moved. Suppress these.
const gfx::Rect new_bounds = native_widget_mac_->GetWindowBoundsInScreen();
if (new_bounds.origin() == last_window_frame_origin_)
return;
last_window_frame_origin_ = new_bounds.origin();
native_widget_mac_->GetWidget()->OnNativeWidgetMove();
} }
void BridgedNativeWidget::OnVisibilityChanged() { void BridgedNativeWidget::OnVisibilityChanged() {
...@@ -769,9 +749,11 @@ void BridgedNativeWidget::OnVisibilityChanged() { ...@@ -769,9 +749,11 @@ void BridgedNativeWidget::OnVisibilityChanged() {
[parent_->GetNSWindow() removeChildWindow:window_]; [parent_->GetNSWindow() removeChildWindow:window_];
} }
// Inform the compositor of the view's size before making it visible. // Showing a translucent window after hiding it should trigger shadow
if (window_visible_) // invalidation.
UpdateCompositorSizeAndScale(); if (window_visible && ![window_ isOpaque])
invalidate_shadow_on_frame_swap_ = true;
UpdateCompositorVisibility(); UpdateCompositorVisibility();
NotifyVisibilityChangeDown(); NotifyVisibilityChangeDown();
native_widget_mac_->GetWidget()->OnNativeWidgetVisibilityChanged( native_widget_mac_->GetWidget()->OnNativeWidgetVisibilityChanged(
...@@ -789,7 +771,7 @@ void BridgedNativeWidget::OnSystemControlTintChanged() { ...@@ -789,7 +771,7 @@ void BridgedNativeWidget::OnSystemControlTintChanged() {
} }
void BridgedNativeWidget::OnBackingPropertiesChanged() { void BridgedNativeWidget::OnBackingPropertiesChanged() {
UpdateCompositorSizeAndScale(); UpdateWindowDisplay();
} }
void BridgedNativeWidget::OnWindowKeyStatusChangedTo(bool is_key) { void BridgedNativeWidget::OnWindowKeyStatusChangedTo(bool is_key) {
...@@ -867,7 +849,11 @@ void BridgedNativeWidget::InitCompositorView() { ...@@ -867,7 +849,11 @@ void BridgedNativeWidget::InitCompositorView() {
DCHECK(!ca_transaction_sync_suppressed_); DCHECK(!ca_transaction_sync_suppressed_);
} }
UpdateCompositorSizeAndScale(); // Send the initial window geometry and screen properties. Any future changes
// will be forwarded.
UpdateWindowDisplay();
UpdateWindowGeometry();
// Note, except for controls, this will set the layer to be hidden, since it // Note, except for controls, this will set the layer to be hidden, since it
// is only called during initialization. // is only called during initialization.
UpdateCompositorVisibility(); UpdateCompositorVisibility();
...@@ -967,6 +953,15 @@ bool BridgedNativeWidget::ShouldRunCustomAnimationFor( ...@@ -967,6 +953,15 @@ bool BridgedNativeWidget::ShouldRunCustomAnimationFor(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// BridgedNativeWidget, ui::CATransactionObserver // BridgedNativeWidget, ui::CATransactionObserver
void BridgedNativeWidget::OnDisplayMetricsChanged(
const display::Display& display,
uint32_t metrics) {
UpdateWindowDisplay();
}
////////////////////////////////////////////////////////////////////////////////
// BridgedNativeWidget, ui::CATransactionObserver
bool BridgedNativeWidget::ShouldWaitInPreCommit() { bool BridgedNativeWidget::ShouldWaitInPreCommit() {
if (!window_visible_) if (!window_visible_)
return false; return false;
...@@ -974,7 +969,7 @@ bool BridgedNativeWidget::ShouldWaitInPreCommit() { ...@@ -974,7 +969,7 @@ bool BridgedNativeWidget::ShouldWaitInPreCommit() {
return false; return false;
if (!compositor_superview_) if (!compositor_superview_)
return false; return false;
return GetClientAreaSize() != compositor_frame_dip_size_; return content_dip_size_ != compositor_frame_dip_size_;
} }
base::TimeDelta BridgedNativeWidget::PreCommitTimeout() { base::TimeDelta BridgedNativeWidget::PreCommitTimeout() {
...@@ -1006,7 +1001,7 @@ void BridgedNativeWidget::SetCALayerParams( ...@@ -1006,7 +1001,7 @@ void BridgedNativeWidget::SetCALayerParams(
// should arrive soon. // should arrive soon.
gfx::Size frame_dip_size = gfx::ConvertSizeToDIP(ca_layer_params.scale_factor, gfx::Size frame_dip_size = gfx::ConvertSizeToDIP(ca_layer_params.scale_factor,
ca_layer_params.pixel_size); ca_layer_params.pixel_size);
if (GetClientAreaSize() != frame_dip_size) if (content_dip_size_ != frame_dip_size)
return; return;
compositor_frame_dip_size_ = frame_dip_size; compositor_frame_dip_size_ = frame_dip_size;
...@@ -1127,11 +1122,6 @@ void BridgedNativeWidget::NotifyVisibilityChangeDown() { ...@@ -1127,11 +1122,6 @@ void BridgedNativeWidget::NotifyVisibilityChangeDown() {
CountBridgedWindows([window_ childWindows])); CountBridgedWindows([window_ childWindows]));
} }
gfx::Size BridgedNativeWidget::GetClientAreaSize() const {
NSRect content_rect = [window_ contentRectForFrameRect:[window_ frame]];
return gfx::Size(NSWidth(content_rect), NSHeight(content_rect));
}
void BridgedNativeWidget::AddCompositorSuperview() { void BridgedNativeWidget::AddCompositorSuperview() {
DCHECK(!compositor_superview_); DCHECK(!compositor_superview_);
compositor_superview_.reset( compositor_superview_.reset(
...@@ -1161,25 +1151,29 @@ void BridgedNativeWidget::AddCompositorSuperview() { ...@@ -1161,25 +1151,29 @@ void BridgedNativeWidget::AddCompositorSuperview() {
[bridged_view_ addSubview:compositor_superview_]; [bridged_view_ addSubview:compositor_superview_];
} }
void BridgedNativeWidget::UpdateCompositorSizeAndScale() { void BridgedNativeWidget::UpdateWindowGeometry() {
// Avoid transient updates during initialization by waiting until after gfx::Rect window_in_screen = gfx::ScreenRectFromNSRect([window_ frame]);
// |compositor_superview_| is created. gfx::Rect content_in_screen = gfx::ScreenRectFromNSRect(
if (!compositor_superview_) [window_ contentRectForFrameRect:[window_ frame]]);
return; bool content_resized = content_dip_size_ != content_in_screen.size();
float scale_factor = GetDeviceScaleFactorFromView(compositor_superview_); content_dip_size_ = content_in_screen.size();
gfx::Size size_in_dip = GetClientAreaSize();
if (!ca_transaction_sync_suppressed_) host_->OnWindowGeometryChanged(window_in_screen, content_in_screen);
ui::CATransactionCoordinator::Get().Synchronize();
host_->SetCompositorSize(size_in_dip, scale_factor); if (content_resized && !ca_transaction_sync_suppressed_)
ui::CATransactionCoordinator::Get().Synchronize();
// For a translucent window, the shadow calculation needs to be carried out // For a translucent window, the shadow calculation needs to be carried out
// after the frame from the compositor arrives. // after the frame from the compositor arrives.
if (![window_ isOpaque]) if (content_resized && ![window_ isOpaque])
invalidate_shadow_on_frame_swap_ = true; invalidate_shadow_on_frame_swap_ = true;
} }
void BridgedNativeWidget::UpdateWindowDisplay() {
host_->OnWindowDisplayChanged(
display::Screen::GetScreen()->GetDisplayNearestWindow(window_));
}
void BridgedNativeWidget::ShowAsModalSheet() { void BridgedNativeWidget::ShowAsModalSheet() {
// -[NSApp beginSheet:] will block the UI thread while the animation runs. // -[NSApp beginSheet:] will block the UI thread while the animation runs.
// So that it doesn't animate a fully transparent window, first wait for a // So that it doesn't animate a fully transparent window, first wait for a
......
...@@ -19,15 +19,12 @@ class VIEWS_EXPORT BridgedNativeWidgetHost { ...@@ -19,15 +19,12 @@ class VIEWS_EXPORT BridgedNativeWidgetHost {
public: public:
virtual ~BridgedNativeWidgetHost() = default; virtual ~BridgedNativeWidgetHost() = default;
// Update the ui::Compositor and ui::Layer's size.
virtual void SetCompositorSize(const gfx::Size& size_in_dip,
float scale_factor) = 0;
// Update the ui::Compositor and ui::Layer's visibility. // Update the ui::Compositor and ui::Layer's visibility.
virtual void SetCompositorVisibility(bool visible) = 0; virtual void SetCompositorVisibility(bool visible) = 0;
// Resize the underlying views::View to |new_size|. // Resize the underlying views::View to |new_size|. Note that this will not
virtual void SetSize(const gfx::Size& new_size) = 0; // necessarily match the content bounds from OnWindowGeometryChanged.
virtual void SetViewSize(const gfx::Size& new_size) = 0;
// Indicate if full keyboard accessibility is needed and updates focus if // Indicate if full keyboard accessibility is needed and updates focus if
// needed. // needed.
...@@ -57,6 +54,15 @@ class VIEWS_EXPORT BridgedNativeWidgetHost { ...@@ -57,6 +54,15 @@ class VIEWS_EXPORT BridgedNativeWidgetHost {
gfx::DecoratedText* decorated_word, gfx::DecoratedText* decorated_word,
gfx::Point* baseline_point) = 0; gfx::Point* baseline_point) = 0;
// Called whenever the NSWindow's size or position changes.
virtual void OnWindowGeometryChanged(
const gfx::Rect& window_bounds_in_screen_dips,
const gfx::Rect& content_bounds_in_screen_dips) = 0;
// Called when the current display or the properties of the current display
// change.
virtual void OnWindowDisplayChanged(const display::Display& display) = 0;
// Called before the NSWindow is closed and destroyed. // Called before the NSWindow is closed and destroyed.
virtual void OnWindowWillClose() = 0; virtual void OnWindowWillClose() = 0;
......
...@@ -65,14 +65,28 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl ...@@ -65,14 +65,28 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl
// See widget.h for documentation. // See widget.h for documentation.
ui::InputMethod* GetInputMethod(); ui::InputMethod* GetInputMethod();
// Geometry of the window, in DIPs.
const gfx::Rect& GetWindowBoundsInScreen() const {
DCHECK(has_received_window_geometry_);
return window_bounds_in_screen_;
}
// Geometry of the content area of the window, in DIPs. Note that this is not
// necessarily the same as the views::View's size.
const gfx::Rect& GetContentBoundsInScreen() const {
DCHECK(has_received_window_geometry_);
return content_bounds_in_screen_;
}
// The display that the window is currently on (or best guess thereof).
const display::Display& GetCurrentDisplay() const { return display_; }
private: private:
void DestroyCompositor(); void DestroyCompositor();
// views::BridgedNativeWidgetHost: // views::BridgedNativeWidgetHost:
void SetCompositorSize(const gfx::Size& size_in_dip,
float scale_factor) override;
void SetCompositorVisibility(bool visible) override; void SetCompositorVisibility(bool visible) override;
void SetSize(const gfx::Size& new_size) override; void SetViewSize(const gfx::Size& new_size) override;
void SetKeyboardAccessible(bool enabled) override; void SetKeyboardAccessible(bool enabled) override;
void SetIsFirstResponder(bool is_first_responder) override; void SetIsFirstResponder(bool is_first_responder) override;
void OnScrollEvent(const ui::ScrollEvent& const_event) override; void OnScrollEvent(const ui::ScrollEvent& const_event) override;
...@@ -86,6 +100,10 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl ...@@ -86,6 +100,10 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl
bool* found_word, bool* found_word,
gfx::DecoratedText* decorated_word, gfx::DecoratedText* decorated_word,
gfx::Point* baseline_point) override; gfx::Point* baseline_point) override;
void OnWindowGeometryChanged(
const gfx::Rect& window_bounds_in_screen_dips,
const gfx::Rect& content_bounds_in_screen_dips) override;
void OnWindowDisplayChanged(const display::Display& display) override;
void OnWindowWillClose() override; void OnWindowWillClose() override;
void OnWindowHasClosed() override; void OnWindowHasClosed() override;
...@@ -119,6 +137,14 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl ...@@ -119,6 +137,14 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl
std::unique_ptr<ui::InputMethod> input_method_; std::unique_ptr<ui::InputMethod> input_method_;
FocusManager* focus_manager_ = nullptr; // Weak. Owned by our Widget. FocusManager* focus_manager_ = nullptr; // Weak. Owned by our Widget.
// The display that the window is currently on.
display::Display display_;
// The geometry of the window and its contents view, in screen coordinates.
bool has_received_window_geometry_ = false;
gfx::Rect window_bounds_in_screen_;
gfx::Rect content_bounds_in_screen_;
std::unique_ptr<ui::RecyclableCompositorMac> compositor_; std::unique_ptr<ui::RecyclableCompositorMac> compositor_;
DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidgetHostImpl); DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidgetHostImpl);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "ui/base/ime/input_method.h" #include "ui/base/ime/input_method.h"
#include "ui/base/ime/input_method_factory.h" #include "ui/base/ime/input_method_factory.h"
#include "ui/compositor/recyclable_compositor_mac.h" #include "ui/compositor/recyclable_compositor_mac.h"
#include "ui/display/screen.h"
#include "ui/gfx/geometry/dip_util.h" #include "ui/gfx/geometry/dip_util.h"
#include "ui/views/cocoa/bridged_native_widget.h" #include "ui/views/cocoa/bridged_native_widget.h"
#include "ui/views/views_delegate.h" #include "ui/views/views_delegate.h"
...@@ -136,14 +137,6 @@ ui::InputMethod* BridgedNativeWidgetHostImpl::GetInputMethod() { ...@@ -136,14 +137,6 @@ ui::InputMethod* BridgedNativeWidgetHostImpl::GetInputMethod() {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// BridgedNativeWidgetHostImpl, views::BridgedNativeWidgetHost: // BridgedNativeWidgetHostImpl, views::BridgedNativeWidgetHost:
void BridgedNativeWidgetHostImpl::SetCompositorSize(
const gfx::Size& size_in_dip,
float scale_factor) {
layer()->SetBounds(gfx::Rect(size_in_dip));
compositor_->UpdateSurface(ConvertSizeToPixel(scale_factor, size_in_dip),
scale_factor);
}
void BridgedNativeWidgetHostImpl::SetCompositorVisibility(bool window_visible) { void BridgedNativeWidgetHostImpl::SetCompositorVisibility(bool window_visible) {
layer()->SetVisible(window_visible); layer()->SetVisible(window_visible);
if (window_visible) { if (window_visible) {
...@@ -172,7 +165,7 @@ void BridgedNativeWidgetHostImpl::OnGestureEvent( ...@@ -172,7 +165,7 @@ void BridgedNativeWidgetHostImpl::OnGestureEvent(
root_view_->GetWidget()->OnGestureEvent(&event); root_view_->GetWidget()->OnGestureEvent(&event);
} }
void BridgedNativeWidgetHostImpl::SetSize(const gfx::Size& new_size) { void BridgedNativeWidgetHostImpl::SetViewSize(const gfx::Size& new_size) {
root_view_->SetSize(new_size); root_view_->SetSize(new_size);
} }
...@@ -240,6 +233,53 @@ void BridgedNativeWidgetHostImpl::GetWordAt( ...@@ -240,6 +233,53 @@ void BridgedNativeWidgetHostImpl::GetWordAt(
*found_word = true; *found_word = true;
} }
void BridgedNativeWidgetHostImpl::OnWindowGeometryChanged(
const gfx::Rect& new_window_bounds_in_screen,
const gfx::Rect& new_content_bounds_in_screen) {
has_received_window_geometry_ = true;
bool window_has_moved =
new_window_bounds_in_screen.origin() != window_bounds_in_screen_.origin();
bool content_has_resized =
new_content_bounds_in_screen.size() != content_bounds_in_screen_.size();
window_bounds_in_screen_ = new_window_bounds_in_screen;
content_bounds_in_screen_ = new_content_bounds_in_screen;
// When a window grows vertically, the AppKit origin changes, but as far as
// tookit-views is concerned, the window hasn't moved. Suppress these.
if (window_has_moved)
native_widget_mac_->GetWidget()->OnNativeWidgetMove();
// Note we can't use new_window_bounds_in_screen.size(), since it includes the
// titlebar for the purposes of detecting a window move.
if (content_has_resized)
native_widget_mac_->GetWidget()->OnNativeWidgetSizeChanged(
content_bounds_in_screen_.size());
// Update the compositor surface and layer size.
if (compositor_) {
gfx::Size surface_size_in_dip = content_bounds_in_screen_.size();
layer()->SetBounds(gfx::Rect(surface_size_in_dip));
compositor_->UpdateSurface(
ConvertSizeToPixel(display_.device_scale_factor(), surface_size_in_dip),
display_.device_scale_factor());
}
}
void BridgedNativeWidgetHostImpl::OnWindowDisplayChanged(
const display::Display& new_display) {
bool scale_factor_changed =
display_.device_scale_factor() != new_display.device_scale_factor();
display_ = new_display;
if (scale_factor_changed && compositor_ && has_received_window_geometry_) {
compositor_->UpdateSurface(
ConvertSizeToPixel(display_.device_scale_factor(),
content_bounds_in_screen_.size()),
display_.device_scale_factor());
}
}
void BridgedNativeWidgetHostImpl::OnWindowWillClose() { void BridgedNativeWidgetHostImpl::OnWindowWillClose() {
Widget* widget = native_widget_mac_->GetWidget(); Widget* widget = native_widget_mac_->GetWidget();
if (DialogDelegate* dialog = widget->widget_delegate()->AsDialogDelegate()) if (DialogDelegate* dialog = widget->widget_delegate()->AsDialogDelegate())
......
...@@ -311,13 +311,11 @@ void NativeWidgetMac::InitModalType(ui::ModalType modal_type) { ...@@ -311,13 +311,11 @@ void NativeWidgetMac::InitModalType(ui::ModalType modal_type) {
} }
gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const { gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const {
return gfx::ScreenRectFromNSRect([GetNativeWindow() frame]); return bridge_host_ ? bridge_host_->GetWindowBoundsInScreen() : gfx::Rect();
} }
gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const { gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const {
NSWindow* window = GetNativeWindow(); return bridge_host_ ? bridge_host_->GetContentBoundsInScreen() : gfx::Rect();
return gfx::ScreenRectFromNSRect(
[window contentRectForFrameRect:[window frame]]);
} }
gfx::Rect NativeWidgetMac::GetRestoredBounds() const { gfx::Rect NativeWidgetMac::GetRestoredBounds() const {
...@@ -601,7 +599,8 @@ void NativeWidgetMac::ClearNativeFocus() { ...@@ -601,7 +599,8 @@ void NativeWidgetMac::ClearNativeFocus() {
} }
gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const { gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const {
return gfx::ScreenRectFromNSRect([[GetNativeWindow() screen] visibleFrame]); return bridge_host_ ? bridge_host_->GetCurrentDisplay().work_area()
: gfx::Rect();
} }
Widget::MoveLoopResult NativeWidgetMac::RunMoveLoop( Widget::MoveLoopResult NativeWidgetMac::RunMoveLoop(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment