Commit 188c284e authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

RemoteMacViews: Update visibility, miniaturize, and key window state

Mechanically move the following functions either from
BridgedNativeWidget to BridgedNativeWidgetPublic or from direct
manipulation in NativeWidgetMac to BridgedNativeWidgetPublic:
  - SetVisibilityState
  - SetVisibleOnAllSpaces
  - SetMiniaturized
  - SetOpacity
  - SetContentAspectRatio
  - SetWindowTitle
  - MakeFirstResponder

Add state tracking for visibility, miniaturization, and window key
status to BridgedNativeWidgetHostImpl.

Merge the new visibility tracking in with the existing compositor
visibility tracking.

Bug: 859152
Change-Id: I750986e6732bc54ff12e90a75e9d649a34895682
Reviewed-on: https://chromium-review.googlesource.com/1182962
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584811}
parent f2c5c920
...@@ -46,6 +46,14 @@ class View; ...@@ -46,6 +46,14 @@ class View;
// BridgedNativeWidget to BridgedNativeWidgetImpl. // BridgedNativeWidget to BridgedNativeWidgetImpl.
class VIEWS_EXPORT BridgedNativeWidgetPublic { class VIEWS_EXPORT BridgedNativeWidgetPublic {
public: public:
// Ways of changing the visibility of the bridged NSWindow.
enum WindowVisibilityState {
HIDE_WINDOW, // Hides with -[NSWindow orderOut:].
SHOW_AND_ACTIVATE_WINDOW, // Shows with -[NSWindow makeKeyAndOrderFront:].
SHOW_INACTIVE, // Shows with -[NSWindow orderWindow:..]. Orders
// the window above its parent if it has one.
};
// Initialize the view to display compositor output. This will send the // Initialize the view to display compositor output. This will send the
// current visibility and dimensions (and any future updates) to the // current visibility and dimensions (and any future updates) to the
// BridgedNativeWidgetHost. // BridgedNativeWidgetHost.
...@@ -67,19 +75,42 @@ class VIEWS_EXPORT BridgedNativeWidgetPublic { ...@@ -67,19 +75,42 @@ class VIEWS_EXPORT BridgedNativeWidgetPublic {
virtual void SetBounds(const gfx::Rect& new_bounds, virtual void SetBounds(const gfx::Rect& new_bounds,
const gfx::Size& minimum_content_size) = 0; const gfx::Size& minimum_content_size) = 0;
// Sets the desired visibility of the window and updates the visibility of
// descendant windows where necessary.
virtual void SetVisibilityState(WindowVisibilityState new_state) = 0;
// Sets the collection behavior so that the window will or will not be visible
// on all spaces.
virtual void SetVisibleOnAllSpaces(bool always_visible) = 0;
// Called by NativeWidgetMac to initiate a transition to the specified target // Called by NativeWidgetMac to initiate a transition to the specified target
// fullscreen state. // fullscreen state.
virtual void SetFullscreen(bool fullscreen) = 0; virtual void SetFullscreen(bool fullscreen) = 0;
// Miniaturize or deminiaturize the window.
virtual void SetMiniaturized(bool miniaturized) = 0;
// Called by NativeWidgetMac when the window size constraints change. // Called by NativeWidgetMac when the window size constraints change.
virtual void SetSizeConstraints(const gfx::Size& min_size, virtual void SetSizeConstraints(const gfx::Size& min_size,
const gfx::Size& max_size, const gfx::Size& max_size,
bool is_resizable, bool is_resizable,
bool is_maximizable) = 0; bool is_maximizable) = 0;
// Set the opacity of the NSWindow.
virtual void SetOpacity(float opacity) = 0;
// Set the content aspect ratio of the NSWindow.
virtual void SetContentAspectRatio(const gfx::SizeF& aspect_ratio) = 0;
// Specify the content to draw in the NSView. // Specify the content to draw in the NSView.
virtual void SetCALayerParams(const gfx::CALayerParams& ca_layer_params) = 0; virtual void SetCALayerParams(const gfx::CALayerParams& ca_layer_params) = 0;
// Set the NSWindow's title text.
virtual void SetWindowTitle(const base::string16& title) = 0;
// Make the content view be the first responder for the NSWindow.
virtual void MakeFirstResponder() = 0;
// Clear the touchbar. // Clear the touchbar.
virtual void ClearTouchBar() = 0; virtual void ClearTouchBar() = 0;
}; };
...@@ -97,14 +128,6 @@ class VIEWS_EXPORT BridgedNativeWidget ...@@ -97,14 +128,6 @@ class VIEWS_EXPORT BridgedNativeWidget
// Contains NativeViewHost->gfx::NativeView associations. // Contains NativeViewHost->gfx::NativeView associations.
using AssociatedViews = std::map<const views::View*, NSView*>; using AssociatedViews = std::map<const views::View*, NSView*>;
// Ways of changing the visibility of the bridged NSWindow.
enum WindowVisibilityState {
HIDE_WINDOW, // Hides with -[NSWindow orderOut:].
SHOW_AND_ACTIVATE_WINDOW, // Shows with -[NSWindow makeKeyAndOrderFront:].
SHOW_INACTIVE, // Shows with -[NSWindow orderWindow:..]. Orders
// the window above its parent if it has one.
};
// Return the size that |window| will take for the given client area |size|, // Return the size that |window| will take for the given client area |size|,
// based on its current style mask. // based on its current style mask.
static gfx::Size GetWindowSizeForClientSize(NSWindow* window, static gfx::Size GetWindowSizeForClientSize(NSWindow* window,
...@@ -134,10 +157,6 @@ class VIEWS_EXPORT BridgedNativeWidget ...@@ -134,10 +157,6 @@ class VIEWS_EXPORT BridgedNativeWidget
// take ownership of |view|. // take ownership of |view|.
void SetRootView(views::View* view); void SetRootView(views::View* view);
// Sets the desired visibility of the window and updates the visibility of
// descendant windows where necessary.
void SetVisibilityState(WindowVisibilityState new_state);
// Acquiring mouse capture first steals capture from any existing // Acquiring mouse capture first steals capture from any existing
// CocoaMouseCaptureDelegate, then captures all mouse events until released. // CocoaMouseCaptureDelegate, then captures all mouse events until released.
void AcquireCapture(); void AcquireCapture();
...@@ -262,12 +281,19 @@ class VIEWS_EXPORT BridgedNativeWidget ...@@ -262,12 +281,19 @@ class VIEWS_EXPORT BridgedNativeWidget
const gfx::Vector2d& parent_offset) override; const gfx::Vector2d& parent_offset) override;
void SetBounds(const gfx::Rect& new_bounds, void SetBounds(const gfx::Rect& new_bounds,
const gfx::Size& minimum_content_size) override; const gfx::Size& minimum_content_size) override;
void SetVisibilityState(WindowVisibilityState new_state) override;
void SetVisibleOnAllSpaces(bool always_visible) override;
void SetFullscreen(bool fullscreen) override; void SetFullscreen(bool fullscreen) override;
void SetMiniaturized(bool miniaturized) override;
void SetSizeConstraints(const gfx::Size& min_size, void SetSizeConstraints(const gfx::Size& min_size,
const gfx::Size& max_size, const gfx::Size& max_size,
bool is_resizable, bool is_resizable,
bool is_maximizable) override; bool is_maximizable) override;
void SetOpacity(float opacity) override;
void SetContentAspectRatio(const gfx::SizeF& aspect_ratio) override;
void SetCALayerParams(const gfx::CALayerParams& ca_layer_params) override; void SetCALayerParams(const gfx::CALayerParams& ca_layer_params) override;
void SetWindowTitle(const base::string16& title) override;
void MakeFirstResponder() override;
void ClearTouchBar() override; void ClearTouchBar() override;
// TODO(ccameron): This method exists temporarily as we move all direct access // TODO(ccameron): This method exists temporarily as we move all direct access
...@@ -312,11 +338,6 @@ class VIEWS_EXPORT BridgedNativeWidget ...@@ -312,11 +338,6 @@ class VIEWS_EXPORT BridgedNativeWidget
bool IsVisibleParent() const override; bool IsVisibleParent() const override;
void RemoveChildWindow(BridgedNativeWidget* child) override; void RemoveChildWindow(BridgedNativeWidget* child) override;
// Set |layer()| to be visible or not visible based on |window_visible_|. If
// the layer is not visible, then lock the compositor, so we don't draw any
// new frames.
void UpdateCompositorVisibility();
BridgedNativeWidgetHost* const host_; // Weak. Owns this. BridgedNativeWidgetHost* const host_; // Weak. Owns this.
NativeWidgetMac* const native_widget_mac_; // Weak. Owns |host_|. NativeWidgetMac* const native_widget_mac_; // Weak. Owns |host_|.
base::scoped_nsobject<NativeWidgetMacNSWindow> window_; base::scoped_nsobject<NativeWidgetMacNSWindow> window_;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/mac/mac_util.h" #include "base/mac/mac_util.h"
#import "base/mac/sdk_forward_declarations.h" #import "base/mac/sdk_forward_declarations.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/strings/sys_string_conversions.h"
#include "components/viz/common/features.h" #include "components/viz/common/features.h"
#include "components/viz/common/surfaces/local_surface_id.h" #include "components/viz/common/surfaces/local_surface_id.h"
#include "ui/accelerated_widget_mac/window_resize_helper_mac.h" #include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
...@@ -711,10 +712,8 @@ void BridgedNativeWidget::OnVisibilityChanged() { ...@@ -711,10 +712,8 @@ void BridgedNativeWidget::OnVisibilityChanged() {
if (window_visible && ![window_ isOpaque]) if (window_visible && ![window_ isOpaque])
invalidate_shadow_on_frame_swap_ = true; invalidate_shadow_on_frame_swap_ = true;
UpdateCompositorVisibility();
NotifyVisibilityChangeDown(); NotifyVisibilityChangeDown();
native_widget_mac_->GetWidget()->OnNativeWidgetVisibilityChanged( host_->OnVisibilityChanged(window_visible_);
window_visible_);
// Toolkit-views suppresses redraws while not visible. To prevent Cocoa asking // Toolkit-views suppresses redraws while not visible. To prevent Cocoa asking
// for an "empty" draw, disable auto-display while hidden. For example, this // for an "empty" draw, disable auto-display while hidden. For example, this
...@@ -732,23 +731,9 @@ void BridgedNativeWidget::OnBackingPropertiesChanged() { ...@@ -732,23 +731,9 @@ void BridgedNativeWidget::OnBackingPropertiesChanged() {
} }
void BridgedNativeWidget::OnWindowKeyStatusChangedTo(bool is_key) { void BridgedNativeWidget::OnWindowKeyStatusChangedTo(bool is_key) {
Widget* widget = native_widget_mac()->GetWidget(); host_->OnWindowKeyStatusChanged(
if (!widget->OnNativeWidgetActivationChanged(is_key)) is_key, [window_ contentView] == [window_ firstResponder],
return; [NSApp isFullKeyboardAccessEnabled]);
// The contentView is the BridgedContentView hosting the views::RootView. The
// focus manager will already know if a native subview has focus.
if ([window_ contentView] == [window_ firstResponder]) {
if (is_key) {
widget->OnNativeFocus();
// Explicitly set the keyboard accessibility state on regaining key
// window status.
[bridged_view_ updateFullKeyboardAccess];
widget->GetFocusManager()->RestoreFocusedView();
} else {
widget->OnNativeBlur();
widget->GetFocusManager()->StoreFocusedView(true);
}
}
} }
void BridgedNativeWidget::SetSizeConstraints(const gfx::Size& min_size, void BridgedNativeWidget::SetSizeConstraints(const gfx::Size& min_size,
...@@ -801,10 +786,6 @@ void BridgedNativeWidget::InitCompositorView() { ...@@ -801,10 +786,6 @@ void BridgedNativeWidget::InitCompositorView() {
// will be forwarded. // will be forwarded.
UpdateWindowDisplay(); UpdateWindowDisplay();
UpdateWindowGeometry(); UpdateWindowGeometry();
// Note, except for controls, this will set the layer to be hidden, since it
// is only called during initialization.
UpdateCompositorVisibility();
} }
void BridgedNativeWidget::SetAssociationForView(const views::View* view, void BridgedNativeWidget::SetAssociationForView(const views::View* view,
...@@ -947,12 +928,39 @@ NSWindow* BridgedNativeWidget::GetWindow() const { ...@@ -947,12 +928,39 @@ NSWindow* BridgedNativeWidget::GetWindow() const {
// TODO(ccameron): Update class names to: // TODO(ccameron): Update class names to:
// BridgedNativeWidgetImpl, BridgedNativeWidget: // BridgedNativeWidgetImpl, BridgedNativeWidget:
void BridgedNativeWidget::SetVisibleOnAllSpaces(bool always_visible) {
gfx::SetNSWindowVisibleOnAllWorkspaces(window_, always_visible);
}
void BridgedNativeWidget::SetFullscreen(bool fullscreen) { void BridgedNativeWidget::SetFullscreen(bool fullscreen) {
if (fullscreen == target_fullscreen_state_) if (fullscreen == target_fullscreen_state_)
return; return;
ToggleDesiredFullscreenState(); ToggleDesiredFullscreenState();
} }
void BridgedNativeWidget::SetMiniaturized(bool miniaturized) {
if (miniaturized) {
// Calling performMiniaturize: will momentarily highlight the button, but
// AppKit will reject it if there is no miniaturize button.
if ([window_ styleMask] & NSMiniaturizableWindowMask)
[window_ performMiniaturize:nil];
else
[window_ miniaturize:nil];
} else {
[window_ deminiaturize:nil];
}
}
void BridgedNativeWidget::SetOpacity(float opacity) {
[window_ setAlphaValue:opacity];
}
void BridgedNativeWidget::SetContentAspectRatio(
const gfx::SizeF& aspect_ratio) {
[window_ setContentAspectRatio:NSMakeSize(aspect_ratio.width(),
aspect_ratio.height())];
}
void BridgedNativeWidget::SetCALayerParams( void BridgedNativeWidget::SetCALayerParams(
const gfx::CALayerParams& ca_layer_params) { const gfx::CALayerParams& ca_layer_params) {
// Ignore frames arriving "late" for an old size. A frame at the new size // Ignore frames arriving "late" for an old size. A frame at the new size
...@@ -976,6 +984,15 @@ void BridgedNativeWidget::SetCALayerParams( ...@@ -976,6 +984,15 @@ void BridgedNativeWidget::SetCALayerParams(
} }
} }
void BridgedNativeWidget::MakeFirstResponder() {
[window_ makeFirstResponder:bridged_view_];
}
void BridgedNativeWidget::SetWindowTitle(const base::string16& title) {
NSString* new_title = base::SysUTF16ToNSString(title);
[window_ setTitle:new_title];
}
void BridgedNativeWidget::ClearTouchBar() { void BridgedNativeWidget::ClearTouchBar() {
if (@available(macOS 10.12.2, *)) { if (@available(macOS 10.12.2, *)) {
if ([bridged_view_ respondsToSelector:@selector(setTouchBar:)]) if ([bridged_view_ respondsToSelector:@selector(setTouchBar:)])
...@@ -1137,8 +1154,7 @@ void BridgedNativeWidget::ShowAsModalSheet() { ...@@ -1137,8 +1154,7 @@ void BridgedNativeWidget::ShowAsModalSheet() {
// 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
// frame. The first step is to pretend that the window is already visible. // frame. The first step is to pretend that the window is already visible.
window_visible_ = true; window_visible_ = true;
UpdateCompositorVisibility(); host_->OnVisibilityChanged(window_visible_);
native_widget_mac_->GetWidget()->OnNativeWidgetVisibilityChanged(true);
NSWindow* parent_window = parent_->GetNSWindow(); NSWindow* parent_window = parent_->GetNSWindow();
DCHECK(parent_window); DCHECK(parent_window);
...@@ -1165,12 +1181,4 @@ NSMutableDictionary* BridgedNativeWidget::GetWindowProperties() const { ...@@ -1165,12 +1181,4 @@ NSMutableDictionary* BridgedNativeWidget::GetWindowProperties() const {
return properties; return properties;
} }
void BridgedNativeWidget::UpdateCompositorVisibility() {
// Avoid transient updates during initialization by waiting until after
// |compositor_superview_| is created.
if (!compositor_superview_)
return;
host_->SetCompositorVisibility(window_visible_);
}
} // namespace views } // namespace views
...@@ -19,8 +19,8 @@ class VIEWS_EXPORT BridgedNativeWidgetHost { ...@@ -19,8 +19,8 @@ class VIEWS_EXPORT BridgedNativeWidgetHost {
public: public:
virtual ~BridgedNativeWidgetHost() = default; virtual ~BridgedNativeWidgetHost() = default;
// Update the ui::Compositor and ui::Layer's visibility. // Update the views::Widget, ui::Compositor and ui::Layer's visibility.
virtual void SetCompositorVisibility(bool visible) = 0; virtual void OnVisibilityChanged(bool visible) = 0;
// Resize the underlying views::View to |new_size|. Note that this will not // Resize the underlying views::View to |new_size|. Note that this will not
// necessarily match the content bounds from OnWindowGeometryChanged. // necessarily match the content bounds from OnWindowGeometryChanged.
...@@ -69,6 +69,9 @@ class VIEWS_EXPORT BridgedNativeWidgetHost { ...@@ -69,6 +69,9 @@ class VIEWS_EXPORT BridgedNativeWidgetHost {
// then this will only be called when all transitions have competed. // then this will only be called when all transitions have competed.
virtual void OnWindowFullscreenTransitionComplete(bool is_fullscreen) = 0; virtual void OnWindowFullscreenTransitionComplete(bool is_fullscreen) = 0;
// Called when the window is miniaturized or deminiaturized.
virtual void OnWindowMiniaturizedChanged(bool miniaturized) = 0;
// Called when the current display or the properties of the current display // Called when the current display or the properties of the current display
// change. // change.
virtual void OnWindowDisplayChanged(const display::Display& display) = 0; virtual void OnWindowDisplayChanged(const display::Display& display) = 0;
...@@ -78,6 +81,15 @@ class VIEWS_EXPORT BridgedNativeWidgetHost { ...@@ -78,6 +81,15 @@ class VIEWS_EXPORT BridgedNativeWidgetHost {
// Called after the NSWindow has been closed and destroyed. // Called after the NSWindow has been closed and destroyed.
virtual void OnWindowHasClosed() = 0; virtual void OnWindowHasClosed() = 0;
// Called when the NSWindow becomes key or resigns from being key. Additional
// state required for the transition include whether or not the content NSView
// is the first responder for the NSWindow in |is_content_first_responder| and
// whether or not the NSApp's full keyboard access is enabled in
// |full_keyboard_access_enabled|.
virtual void OnWindowKeyStatusChanged(bool is_key,
bool is_content_first_responder,
bool full_keyboard_access_enabled) = 0;
}; };
} // namespace views } // namespace views
......
...@@ -76,6 +76,9 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl ...@@ -76,6 +76,9 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl
// This does NOT take ownership of |focus_manager|. // This does NOT take ownership of |focus_manager|.
void SetFocusManager(FocusManager* focus_manager); void SetFocusManager(FocusManager* focus_manager);
// Set the window's title, returning true if the title has changed.
bool SetWindowTitle(const base::string16& title);
// Called when the owning Widget's Init method has completed. // Called when the owning Widget's Init method has completed.
void OnWidgetInitDone(); void OnWidgetInitDone();
...@@ -102,12 +105,17 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl ...@@ -102,12 +105,17 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl
// fullscreen or transitioning between fullscreen states. // fullscreen or transitioning between fullscreen states.
gfx::Rect GetRestoredBounds() const; gfx::Rect GetRestoredBounds() const;
bool IsVisible() const { return is_visible_; }
bool IsMiniaturized() const { return is_miniaturized_; }
bool IsWindowKey() const { return is_window_key_; }
private: private:
gfx::Vector2d GetBoundsOffsetForParent() const; gfx::Vector2d GetBoundsOffsetForParent() const;
void UpdateCompositorProperties();
void DestroyCompositor(); void DestroyCompositor();
// views::BridgedNativeWidgetHost: // views::BridgedNativeWidgetHost:
void SetCompositorVisibility(bool visible) override; void OnVisibilityChanged(bool visible) override;
void SetViewSize(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;
...@@ -128,9 +136,13 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl ...@@ -128,9 +136,13 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl
void OnWindowFullscreenTransitionStart(bool target_fullscreen_state) override; void OnWindowFullscreenTransitionStart(bool target_fullscreen_state) override;
void OnWindowFullscreenTransitionComplete( void OnWindowFullscreenTransitionComplete(
bool target_fullscreen_state) override; bool target_fullscreen_state) override;
void OnWindowMiniaturizedChanged(bool miniaturized) override;
void OnWindowDisplayChanged(const display::Display& display) override; void OnWindowDisplayChanged(const display::Display& display) override;
void OnWindowWillClose() override; void OnWindowWillClose() override;
void OnWindowHasClosed() override; void OnWindowHasClosed() override;
void OnWindowKeyStatusChanged(bool is_key,
bool is_content_first_responder,
bool full_keyboard_access_enabled) override;
// DialogObserver: // DialogObserver:
void OnDialogModelChanged() override; void OnDialogModelChanged() override;
...@@ -164,6 +176,8 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl ...@@ -164,6 +176,8 @@ 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.
base::string16 window_title_;
// The display that the window is currently on. // The display that the window is currently on.
display::Display display_; display::Display display_;
...@@ -171,8 +185,11 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl ...@@ -171,8 +185,11 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl
bool has_received_window_geometry_ = false; bool has_received_window_geometry_ = false;
gfx::Rect window_bounds_in_screen_; gfx::Rect window_bounds_in_screen_;
gfx::Rect content_bounds_in_screen_; gfx::Rect content_bounds_in_screen_;
bool is_visible_ = false;
bool target_fullscreen_state_ = false; bool target_fullscreen_state_ = false;
bool in_fullscreen_transition_ = false; bool in_fullscreen_transition_ = false;
bool is_miniaturized_ = false;
bool is_window_key_ = false;
gfx::Rect window_bounds_before_fullscreen_; gfx::Rect window_bounds_before_fullscreen_;
std::unique_ptr<ui::RecyclableCompositorMac> compositor_; std::unique_ptr<ui::RecyclableCompositorMac> compositor_;
......
...@@ -70,7 +70,7 @@ void BridgedNativeWidgetHostImpl::InitWindow(const Widget::InitParams& params) { ...@@ -70,7 +70,7 @@ void BridgedNativeWidgetHostImpl::InitWindow(const Widget::InitParams& params) {
// Widgets for UI controls (usually layered above web contents) start visible. // Widgets for UI controls (usually layered above web contents) start visible.
if (widget_type_ == Widget::InitParams::TYPE_CONTROL) if (widget_type_ == Widget::InitParams::TYPE_CONTROL)
bridge_impl_->SetVisibilityState(BridgedNativeWidget::SHOW_INACTIVE); bridge()->SetVisibilityState(BridgedNativeWidgetPublic::SHOW_INACTIVE);
} }
void BridgedNativeWidgetHostImpl::SetBounds(const gfx::Rect& bounds) { void BridgedNativeWidgetHostImpl::SetBounds(const gfx::Rect& bounds) {
...@@ -134,12 +134,26 @@ void BridgedNativeWidgetHostImpl::CreateCompositor( ...@@ -134,12 +134,26 @@ void BridgedNativeWidgetHostImpl::CreateCompositor(
translucent ? SK_ColorTRANSPARENT : SK_ColorWHITE); translucent ? SK_ColorTRANSPARENT : SK_ColorWHITE);
compositor_->compositor()->SetRootLayer(layer()); compositor_->compositor()->SetRootLayer(layer());
// The compositor is initially locked (prevented from producing frames), and // The compositor is locked (prevented from producing frames) until the widget
// is only unlocked when the BridgedNativeWidget calls back via // is made visible.
// SetCompositorVisibility. UpdateCompositorProperties();
layer()->SetVisible(is_visible_);
if (is_visible_)
compositor_->Unsuspend();
bridge()->InitCompositorView(); bridge()->InitCompositorView();
} }
void BridgedNativeWidgetHostImpl::UpdateCompositorProperties() {
if (!compositor_)
return;
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::DestroyCompositor() { void BridgedNativeWidgetHostImpl::DestroyCompositor() {
if (layer()) { if (layer()) {
// LayerOwner supports a change in ownership, e.g., to animate a closing // LayerOwner supports a change in ownership, e.g., to animate a closing
...@@ -179,6 +193,14 @@ void BridgedNativeWidgetHostImpl::SetFocusManager(FocusManager* focus_manager) { ...@@ -179,6 +193,14 @@ void BridgedNativeWidgetHostImpl::SetFocusManager(FocusManager* focus_manager) {
OnDidChangeFocus(nullptr, new_focus); OnDidChangeFocus(nullptr, new_focus);
} }
bool BridgedNativeWidgetHostImpl::SetWindowTitle(const base::string16& title) {
if (window_title_ == title)
return false;
window_title_ = title;
bridge()->SetWindowTitle(window_title_);
return true;
}
void BridgedNativeWidgetHostImpl::OnWidgetInitDone() { void BridgedNativeWidgetHostImpl::OnWidgetInitDone() {
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())
...@@ -204,14 +226,19 @@ gfx::Rect BridgedNativeWidgetHostImpl::GetRestoredBounds() const { ...@@ -204,14 +226,19 @@ gfx::Rect BridgedNativeWidgetHostImpl::GetRestoredBounds() const {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// BridgedNativeWidgetHostImpl, views::BridgedNativeWidgetHost: // BridgedNativeWidgetHostImpl, views::BridgedNativeWidgetHost:
void BridgedNativeWidgetHostImpl::SetCompositorVisibility(bool window_visible) { void BridgedNativeWidgetHostImpl::OnVisibilityChanged(bool window_visible) {
layer()->SetVisible(window_visible); is_visible_ = window_visible;
if (window_visible) { if (compositor_) {
compositor_->Unsuspend(); layer()->SetVisible(window_visible);
layer()->SchedulePaint(layer()->bounds()); if (window_visible) {
} else { compositor_->Unsuspend();
compositor_->Suspend(); layer()->SchedulePaint(layer()->bounds());
} else {
compositor_->Suspend();
}
} }
native_widget_mac_->GetWidget()->OnNativeWidgetVisibilityChanged(
window_visible);
} }
void BridgedNativeWidgetHostImpl::OnScrollEvent( void BridgedNativeWidgetHostImpl::OnScrollEvent(
...@@ -325,13 +352,7 @@ void BridgedNativeWidgetHostImpl::OnWindowGeometryChanged( ...@@ -325,13 +352,7 @@ void BridgedNativeWidgetHostImpl::OnWindowGeometryChanged(
content_bounds_in_screen_.size()); content_bounds_in_screen_.size());
// Update the compositor surface and layer size. // Update the compositor surface and layer size.
if (compositor_) { UpdateCompositorProperties();
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::OnWindowFullscreenTransitionStart( void BridgedNativeWidgetHostImpl::OnWindowFullscreenTransitionStart(
...@@ -355,6 +376,11 @@ void BridgedNativeWidgetHostImpl::OnWindowFullscreenTransitionComplete( ...@@ -355,6 +376,11 @@ void BridgedNativeWidgetHostImpl::OnWindowFullscreenTransitionComplete(
native_widget_mac_->OnSizeConstraintsChanged(); native_widget_mac_->OnSizeConstraintsChanged();
} }
void BridgedNativeWidgetHostImpl::OnWindowMiniaturizedChanged(
bool miniaturized) {
is_miniaturized_ = miniaturized;
}
void BridgedNativeWidgetHostImpl::OnWindowDisplayChanged( void BridgedNativeWidgetHostImpl::OnWindowDisplayChanged(
const display::Display& new_display) { const display::Display& new_display) {
bool scale_factor_changed = bool scale_factor_changed =
...@@ -379,6 +405,30 @@ void BridgedNativeWidgetHostImpl::OnWindowHasClosed() { ...@@ -379,6 +405,30 @@ void BridgedNativeWidgetHostImpl::OnWindowHasClosed() {
native_widget_mac_->WindowDestroyed(); native_widget_mac_->WindowDestroyed();
} }
void BridgedNativeWidgetHostImpl::OnWindowKeyStatusChanged(
bool is_key,
bool is_content_first_responder,
bool full_keyboard_access_enabled) {
is_window_key_ = is_key;
Widget* widget = native_widget_mac_->GetWidget();
if (!widget->OnNativeWidgetActivationChanged(is_key))
return;
// The contentView is the BridgedContentView hosting the views::RootView. The
// focus manager will already know if a native subview has focus.
if (is_content_first_responder) {
if (is_key) {
widget->OnNativeFocus();
// Explicitly set the keyboard accessibility state on regaining key
// window status.
SetKeyboardAccessible(full_keyboard_access_enabled);
widget->GetFocusManager()->RestoreFocusedView();
} else {
widget->OnNativeBlur();
widget->GetFocusManager()->StoreFocusedView(true);
}
}
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// BridgedNativeWidgetHostImpl, DialogObserver: // BridgedNativeWidgetHostImpl, DialogObserver:
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#import "ui/views/cocoa/bridged_content_view.h" #import "ui/views/cocoa/bridged_content_view.h"
#import "ui/views/cocoa/bridged_native_widget.h" #import "ui/views/cocoa/bridged_native_widget.h"
#include "ui/views/cocoa/bridged_native_widget_host.h"
#include "ui/views/widget/native_widget_mac.h" #include "ui/views/widget/native_widget_mac.h"
@implementation ViewsNSWindowDelegate @implementation ViewsNSWindowDelegate
...@@ -155,10 +156,12 @@ ...@@ -155,10 +156,12 @@
} }
- (void)windowDidMiniaturize:(NSNotification*)notification { - (void)windowDidMiniaturize:(NSNotification*)notification {
parent_->host()->OnWindowMiniaturizedChanged(true);
parent_->OnVisibilityChanged(); parent_->OnVisibilityChanged();
} }
- (void)windowDidDeminiaturize:(NSNotification*)notification { - (void)windowDidDeminiaturize:(NSNotification*)notification {
parent_->host()->OnWindowMiniaturizedChanged(false);
parent_->OnVisibilityChanged(); parent_->OnVisibilityChanged();
} }
......
...@@ -144,7 +144,7 @@ void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) { ...@@ -144,7 +144,7 @@ void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) {
DCHECK(GetWidget()->GetRootView()); DCHECK(GetWidget()->GetRootView());
bridge_host_->SetRootView(GetWidget()->GetRootView()); bridge_host_->SetRootView(GetWidget()->GetRootView());
if (auto* focus_manager = GetWidget()->GetFocusManager()) { if (auto* focus_manager = GetWidget()->GetFocusManager()) {
[window makeFirstResponder:bridge()->ns_view()]; bridge()->MakeFirstResponder();
bridge_host_->SetFocusManager(focus_manager); bridge_host_->SetFocusManager(focus_manager);
} }
...@@ -279,14 +279,9 @@ void NativeWidgetMac::GetWindowPlacement( ...@@ -279,14 +279,9 @@ void NativeWidgetMac::GetWindowPlacement(
} }
bool NativeWidgetMac::SetWindowTitle(const base::string16& title) { bool NativeWidgetMac::SetWindowTitle(const base::string16& title) {
NSWindow* window = GetNativeWindow(); if (!bridge_host_)
NSString* current_title = [window title];
NSString* new_title = base::SysUTF16ToNSString(title);
if ([current_title isEqualToString:new_title])
return false; return false;
return bridge_host_->SetWindowTitle(title);
[window setTitle:new_title];
return true;
} }
void NativeWidgetMac::SetWindowIcons(const gfx::ImageSkia& window_icon, void NativeWidgetMac::SetWindowIcons(const gfx::ImageSkia& window_icon,
...@@ -451,8 +446,8 @@ void NativeWidgetMac::Show(ui::WindowShowState show_state, ...@@ -451,8 +446,8 @@ void NativeWidgetMac::Show(ui::WindowShowState show_state,
} }
bridge()->SetVisibilityState( bridge()->SetVisibilityState(
show_state == ui::SHOW_STATE_INACTIVE show_state == ui::SHOW_STATE_INACTIVE
? BridgedNativeWidget::SHOW_INACTIVE ? BridgedNativeWidgetPublic::SHOW_INACTIVE
: BridgedNativeWidget::SHOW_AND_ACTIVATE_WINDOW); : BridgedNativeWidgetPublic::SHOW_AND_ACTIVATE_WINDOW);
// Ignore the SetInitialFocus() result. BridgedContentView should get // Ignore the SetInitialFocus() result. BridgedContentView should get
// firstResponder status regardless. // firstResponder status regardless.
...@@ -462,19 +457,18 @@ void NativeWidgetMac::Show(ui::WindowShowState show_state, ...@@ -462,19 +457,18 @@ void NativeWidgetMac::Show(ui::WindowShowState show_state,
void NativeWidgetMac::Hide() { void NativeWidgetMac::Hide() {
if (!bridge()) if (!bridge())
return; return;
bridge()->SetVisibilityState(BridgedNativeWidgetPublic::HIDE_WINDOW);
bridge()->SetVisibilityState(BridgedNativeWidget::HIDE_WINDOW);
} }
bool NativeWidgetMac::IsVisible() const { bool NativeWidgetMac::IsVisible() const {
return bridge() && bridge()->window_visible(); return bridge_host_ && bridge_host_->IsVisible();
} }
void NativeWidgetMac::Activate() { void NativeWidgetMac::Activate() {
if (!bridge()) if (!bridge())
return; return;
bridge()->SetVisibilityState(
bridge()->SetVisibilityState(BridgedNativeWidget::SHOW_AND_ACTIVATE_WINDOW); BridgedNativeWidgetPublic::SHOW_AND_ACTIVATE_WINDOW);
} }
void NativeWidgetMac::Deactivate() { void NativeWidgetMac::Deactivate() {
...@@ -482,7 +476,7 @@ void NativeWidgetMac::Deactivate() { ...@@ -482,7 +476,7 @@ void NativeWidgetMac::Deactivate() {
} }
bool NativeWidgetMac::IsActive() const { bool NativeWidgetMac::IsActive() const {
return [GetNativeWindow() isKeyWindow]; return bridge_host_ ? bridge_host_->IsWindowKey() : false;
} }
void NativeWidgetMac::SetAlwaysOnTop(bool always_on_top) { void NativeWidgetMac::SetAlwaysOnTop(bool always_on_top) {
...@@ -494,7 +488,9 @@ bool NativeWidgetMac::IsAlwaysOnTop() const { ...@@ -494,7 +488,9 @@ bool NativeWidgetMac::IsAlwaysOnTop() const {
} }
void NativeWidgetMac::SetVisibleOnAllWorkspaces(bool always_visible) { void NativeWidgetMac::SetVisibleOnAllWorkspaces(bool always_visible) {
gfx::SetNSWindowVisibleOnAllWorkspaces(GetNativeWindow(), always_visible); if (!bridge())
return;
bridge()->SetVisibleOnAllSpaces(always_visible);
} }
bool NativeWidgetMac::IsVisibleOnAllWorkspaces() const { bool NativeWidgetMac::IsVisibleOnAllWorkspaces() const {
...@@ -506,13 +502,9 @@ void NativeWidgetMac::Maximize() { ...@@ -506,13 +502,9 @@ void NativeWidgetMac::Maximize() {
} }
void NativeWidgetMac::Minimize() { void NativeWidgetMac::Minimize() {
NSWindow* window = GetNativeWindow(); if (!bridge())
// Calling performMiniaturize: will momentarily highlight the button, but return;
// AppKit will reject it if there is no miniaturize button. bridge()->SetMiniaturized(true);
if ([window styleMask] & NSMiniaturizableWindowMask)
[window performMiniaturize:nil];
else
[window miniaturize:nil];
} }
bool NativeWidgetMac::IsMaximized() const { bool NativeWidgetMac::IsMaximized() const {
...@@ -522,12 +514,16 @@ bool NativeWidgetMac::IsMaximized() const { ...@@ -522,12 +514,16 @@ bool NativeWidgetMac::IsMaximized() const {
} }
bool NativeWidgetMac::IsMinimized() const { bool NativeWidgetMac::IsMinimized() const {
return [GetNativeWindow() isMiniaturized]; if (!bridge_host_)
return false;
return bridge_host_->IsMiniaturized();
} }
void NativeWidgetMac::Restore() { void NativeWidgetMac::Restore() {
SetFullscreen(false); if (!bridge())
[GetNativeWindow() deminiaturize:nil]; return;
bridge()->SetFullscreen(false);
bridge()->SetMiniaturized(false);
} }
void NativeWidgetMac::SetFullscreen(bool fullscreen) { void NativeWidgetMac::SetFullscreen(bool fullscreen) {
...@@ -541,12 +537,15 @@ bool NativeWidgetMac::IsFullscreen() const { ...@@ -541,12 +537,15 @@ bool NativeWidgetMac::IsFullscreen() const {
} }
void NativeWidgetMac::SetOpacity(float opacity) { void NativeWidgetMac::SetOpacity(float opacity) {
[GetNativeWindow() setAlphaValue:opacity]; if (!bridge())
return;
bridge()->SetOpacity(opacity);
} }
void NativeWidgetMac::SetAspectRatio(const gfx::SizeF& aspect_ratio) { void NativeWidgetMac::SetAspectRatio(const gfx::SizeF& aspect_ratio) {
[GetNativeWindow() setContentAspectRatio:NSMakeSize(aspect_ratio.width(), if (!bridge())
aspect_ratio.height())]; return;
bridge()->SetContentAspectRatio(aspect_ratio);
} }
void NativeWidgetMac::FlashFrame(bool flash_frame) { void NativeWidgetMac::FlashFrame(bool flash_frame) {
...@@ -595,7 +594,9 @@ void NativeWidgetMac::ClearNativeFocus() { ...@@ -595,7 +594,9 @@ void NativeWidgetMac::ClearNativeFocus() {
// To quote DesktopWindowTreeHostX11, "This method is weird and misnamed." // To quote DesktopWindowTreeHostX11, "This method is weird and misnamed."
// The goal is to set focus to the content window, thereby removing focus from // The goal is to set focus to the content window, thereby removing focus from
// any NSView in the window that doesn't belong to toolkit-views. // any NSView in the window that doesn't belong to toolkit-views.
[GetNativeWindow() makeFirstResponder:GetNativeView()]; if (!bridge())
return;
bridge()->MakeFirstResponder();
} }
gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const { gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const {
......
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