Commit c6995dcb authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

RemoteMacViews: Separate fullscreen state

Make NativeWidgetMac::SetFullscreen go through
BridgedNativeWidgetHostImpl instead of directly manipulating
BridgedNativeWidget. Make note of subtle state tracking behavior in
BridgedNativeWidgetHostImpl::SetFullscreen.

Change BridgedNativeWidget's fullscreen transition functions to go
through the BridgedNativeWidgetHost interface instead of calling into
NativeWidgetMac directly.

Move tracking for GetBoundsForRestore from BridgedNativeWidget to
BridgedNativeWidgetHostImpl.

Change BridgedNativeWidget from pulling size constraints in
BridgedNativeWidget::OnSizeConstraintsChanged to having the
NativeWidgetMac push these constraints to BridgedNativeWidget.

Bug: 859152
Change-Id: Ie33b79becf1ccd1d476e8033cb078d0ffe75463f
Reviewed-on: https://chromium-review.googlesource.com/1182673Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584804}
parent 83e7387a
...@@ -67,6 +67,16 @@ class VIEWS_EXPORT BridgedNativeWidgetPublic { ...@@ -67,6 +67,16 @@ 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;
// Called by NativeWidgetMac to initiate a transition to the specified target
// fullscreen state.
virtual void SetFullscreen(bool fullscreen) = 0;
// Called by NativeWidgetMac when the window size constraints change.
virtual void SetSizeConstraints(const gfx::Size& min_size,
const gfx::Size& max_size,
bool is_resizable,
bool is_maximizable) = 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;
...@@ -184,18 +194,10 @@ class VIEWS_EXPORT BridgedNativeWidget ...@@ -184,18 +194,10 @@ class VIEWS_EXPORT BridgedNativeWidget
// Called by the NSWindowDelegate when the window becomes or resigns key. // Called by the NSWindowDelegate when the window becomes or resigns key.
void OnWindowKeyStatusChangedTo(bool is_key); void OnWindowKeyStatusChangedTo(bool is_key);
// Called by NativeWidgetMac when the window size constraints change.
void OnSizeConstraintsChanged();
// Called by the window show animation when it completes and wants to destroy // Called by the window show animation when it completes and wants to destroy
// itself. // itself.
void OnShowAnimationComplete(); void OnShowAnimationComplete();
// The restored bounds will be derived from the current NSWindow frame unless
// fullscreen or transitioning between fullscreen states.
gfx::Rect GetRestoredBounds() const;
// Updates |associated_views_| on NativeViewHost::Attach()/Detach(). // Updates |associated_views_| on NativeViewHost::Attach()/Detach().
void SetAssociationForView(const views::View* view, NSView* native_view); void SetAssociationForView(const views::View* view, NSView* native_view);
void ClearAssociationForView(const views::View* view); void ClearAssociationForView(const views::View* view);
...@@ -260,6 +262,11 @@ class VIEWS_EXPORT BridgedNativeWidget ...@@ -260,6 +262,11 @@ 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 SetFullscreen(bool fullscreen) override;
void SetSizeConstraints(const gfx::Size& min_size,
const gfx::Size& max_size,
bool is_resizable,
bool is_maximizable) override;
void SetCALayerParams(const gfx::CALayerParams& ca_layer_params) override; void SetCALayerParams(const gfx::CALayerParams& ca_layer_params) override;
void ClearTouchBar() override; void ClearTouchBar() override;
...@@ -323,7 +330,7 @@ class VIEWS_EXPORT BridgedNativeWidget ...@@ -323,7 +330,7 @@ class VIEWS_EXPORT BridgedNativeWidget
Widget::InitParams::Type widget_type_; Widget::InitParams::Type widget_type_;
bool is_translucent_window_ = false; bool is_translucent_window_ = false;
BridgedNativeWidgetOwner* parent_; // Weak. If non-null, owns this. BridgedNativeWidgetOwner* parent_ = nullptr; // Weak. If non-null, owns this.
std::vector<BridgedNativeWidget*> child_windows_; std::vector<BridgedNativeWidget*> child_windows_;
// The size of the content area of the window most recently sent to |host_| // The size of the content area of the window most recently sent to |host_|
...@@ -349,19 +356,19 @@ class VIEWS_EXPORT BridgedNativeWidget ...@@ -349,19 +356,19 @@ class VIEWS_EXPORT BridgedNativeWidget
// Whether this window wants to be fullscreen. If a fullscreen animation is in // Whether this window wants to be fullscreen. If a fullscreen animation is in
// progress then it might not be actually fullscreen. // progress then it might not be actually fullscreen.
bool target_fullscreen_state_; bool target_fullscreen_state_ = false;
// Whether this window is in a fullscreen transition, and the fullscreen state // Whether this window is in a fullscreen transition, and the fullscreen state
// can not currently be changed. // can not currently be changed.
bool in_fullscreen_transition_; bool in_fullscreen_transition_ = false;
// Stores the value last read from -[NSWindow isVisible], to detect visibility // Stores the value last read from -[NSWindow isVisible], to detect visibility
// changes. // changes.
bool window_visible_; bool window_visible_ = false;
// If true, the window is either visible, or wants to be visible but is // If true, the window is either visible, or wants to be visible but is
// currently hidden due to having a hidden parent. // currently hidden due to having a hidden parent.
bool wants_to_be_visible_; bool wants_to_be_visible_ = false;
// If true, then ignore interactions with CATransactionCoordinator until the // If true, then ignore interactions with CATransactionCoordinator until the
// first frame arrives. // first frame arrives.
......
...@@ -207,12 +207,7 @@ BridgedNativeWidget::BridgedNativeWidget(BridgedNativeWidgetHost* host, ...@@ -207,12 +207,7 @@ BridgedNativeWidget::BridgedNativeWidget(BridgedNativeWidgetHost* host,
NativeWidgetMac* parent) NativeWidgetMac* parent)
: host_(host), : host_(host),
native_widget_mac_(parent), native_widget_mac_(parent),
widget_type_(Widget::InitParams::TYPE_WINDOW), // Updated in Init(). widget_type_(Widget::InitParams::TYPE_WINDOW) { // Updated in Init().
parent_(nullptr),
target_fullscreen_state_(false),
in_fullscreen_transition_(false),
window_visible_(false),
wants_to_be_visible_(false) {
DCHECK(parent); DCHECK(parent);
window_delegate_.reset( window_delegate_.reset(
[[ViewsNSWindowDelegate alloc] initWithBridgedNativeWidget:this]); [[ViewsNSWindowDelegate alloc] initWithBridgedNativeWidget:this]);
...@@ -613,12 +608,7 @@ void BridgedNativeWidget::OnFullscreenTransitionStart( ...@@ -613,12 +608,7 @@ void BridgedNativeWidget::OnFullscreenTransitionStart(
target_fullscreen_state_ = target_fullscreen_state; target_fullscreen_state_ = target_fullscreen_state;
in_fullscreen_transition_ = true; in_fullscreen_transition_ = true;
// If going into fullscreen, store an answer for GetRestoredBounds(). host_->OnWindowFullscreenTransitionStart(target_fullscreen_state);
if (target_fullscreen_state)
bounds_before_fullscreen_ = gfx::ScreenRectFromNSRect([window_ frame]);
// Notify that fullscreen state changed.
native_widget_mac_->OnWindowFullscreenStateChange();
} }
void BridgedNativeWidget::OnFullscreenTransitionComplete( void BridgedNativeWidget::OnFullscreenTransitionComplete(
...@@ -626,8 +616,7 @@ void BridgedNativeWidget::OnFullscreenTransitionComplete( ...@@ -626,8 +616,7 @@ void BridgedNativeWidget::OnFullscreenTransitionComplete(
in_fullscreen_transition_ = false; in_fullscreen_transition_ = false;
if (target_fullscreen_state_ == actual_fullscreen_state) { if (target_fullscreen_state_ == actual_fullscreen_state) {
// Ensure constraints are re-applied when completing a transition. host_->OnWindowFullscreenTransitionComplete(actual_fullscreen_state);
OnSizeConstraintsChanged();
return; return;
} }
...@@ -762,21 +751,19 @@ void BridgedNativeWidget::OnWindowKeyStatusChangedTo(bool is_key) { ...@@ -762,21 +751,19 @@ void BridgedNativeWidget::OnWindowKeyStatusChangedTo(bool is_key) {
} }
} }
void BridgedNativeWidget::OnSizeConstraintsChanged() { void BridgedNativeWidget::SetSizeConstraints(const gfx::Size& min_size,
const gfx::Size& max_size,
bool is_resizable,
bool is_maximizable) {
// Don't modify the size constraints or fullscreen collection behavior while // Don't modify the size constraints or fullscreen collection behavior while
// in fullscreen or during a transition. OnFullscreenTransitionComplete will // in fullscreen or during a transition. OnFullscreenTransitionComplete will
// reset these after leaving fullscreen. // reset these after leaving fullscreen.
if (target_fullscreen_state_ || in_fullscreen_transition_) if (target_fullscreen_state_ || in_fullscreen_transition_)
return; return;
Widget* widget = native_widget_mac()->GetWidget();
gfx::Size min_size = widget->GetMinimumSize();
gfx::Size max_size = widget->GetMaximumSize();
bool is_resizable = widget->widget_delegate()->CanResize();
bool shows_resize_controls = bool shows_resize_controls =
is_resizable && (min_size.IsEmpty() || min_size != max_size); is_resizable && (min_size.IsEmpty() || min_size != max_size);
bool shows_fullscreen_controls = bool shows_fullscreen_controls = is_resizable && is_maximizable;
is_resizable && widget->widget_delegate()->CanMaximize();
gfx::ApplyNSWindowSizeConstraints(window_, min_size, max_size, gfx::ApplyNSWindowSizeConstraints(window_, min_size, max_size,
shows_resize_controls, shows_resize_controls,
...@@ -787,13 +774,6 @@ void BridgedNativeWidget::OnShowAnimationComplete() { ...@@ -787,13 +774,6 @@ void BridgedNativeWidget::OnShowAnimationComplete() {
show_animation_.reset(); show_animation_.reset();
} }
gfx::Rect BridgedNativeWidget::GetRestoredBounds() const {
if (target_fullscreen_state_ || in_fullscreen_transition_)
return bounds_before_fullscreen_;
return gfx::ScreenRectFromNSRect([window_ frame]);
}
void BridgedNativeWidget::InitCompositorView() { void BridgedNativeWidget::InitCompositorView() {
AddCompositorSuperview(); AddCompositorSuperview();
...@@ -967,6 +947,12 @@ NSWindow* BridgedNativeWidget::GetWindow() const { ...@@ -967,6 +947,12 @@ NSWindow* BridgedNativeWidget::GetWindow() const {
// TODO(ccameron): Update class names to: // TODO(ccameron): Update class names to:
// BridgedNativeWidgetImpl, BridgedNativeWidget: // BridgedNativeWidgetImpl, BridgedNativeWidget:
void BridgedNativeWidget::SetFullscreen(bool fullscreen) {
if (fullscreen == target_fullscreen_state_)
return;
ToggleDesiredFullscreenState();
}
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
......
...@@ -59,6 +59,16 @@ class VIEWS_EXPORT BridgedNativeWidgetHost { ...@@ -59,6 +59,16 @@ class VIEWS_EXPORT BridgedNativeWidgetHost {
const gfx::Rect& window_bounds_in_screen_dips, const gfx::Rect& window_bounds_in_screen_dips,
const gfx::Rect& content_bounds_in_screen_dips) = 0; const gfx::Rect& content_bounds_in_screen_dips) = 0;
// Called when the window begins transitioning to or from being fullscreen.
virtual void OnWindowFullscreenTransitionStart(
bool target_fullscreen_state) = 0;
// Called when the window has completed its transition to or from being
// fullscreen. Note that if there are multiple consecutive transitions
// (because a new transition was initiated before the previous one completed)
// then this will only be called when all transitions have competed.
virtual void OnWindowFullscreenTransitionComplete(bool is_fullscreen) = 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;
......
...@@ -59,6 +59,13 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl ...@@ -59,6 +59,13 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl
// views::GetAuraWindowTypeForWidgetType does not consider a "popup" type. // views::GetAuraWindowTypeForWidgetType does not consider a "popup" type.
void SetBounds(const gfx::Rect& bounds); void SetBounds(const gfx::Rect& bounds);
// Tell the window to transition to being fullscreen or not-fullscreen.
void SetFullscreen(bool fullscreen);
// The ultimate fullscreen state that is being targeted (irrespective of any
// active transitions).
bool target_fullscreen_state() const { return target_fullscreen_state_; }
// Set the root view (set during initialization and un-set during teardown). // Set the root view (set during initialization and un-set during teardown).
void SetRootView(views::View* root_view); void SetRootView(views::View* root_view);
...@@ -91,6 +98,10 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl ...@@ -91,6 +98,10 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl
// The display that the window is currently on (or best guess thereof). // The display that the window is currently on (or best guess thereof).
const display::Display& GetCurrentDisplay() const { return display_; } const display::Display& GetCurrentDisplay() const { return display_; }
// The restored bounds will be derived from the current NSWindow frame unless
// fullscreen or transitioning between fullscreen states.
gfx::Rect GetRestoredBounds() const;
private: private:
gfx::Vector2d GetBoundsOffsetForParent() const; gfx::Vector2d GetBoundsOffsetForParent() const;
void DestroyCompositor(); void DestroyCompositor();
...@@ -114,6 +125,9 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl ...@@ -114,6 +125,9 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl
void OnWindowGeometryChanged( void OnWindowGeometryChanged(
const gfx::Rect& window_bounds_in_screen_dips, const gfx::Rect& window_bounds_in_screen_dips,
const gfx::Rect& content_bounds_in_screen_dips) override; const gfx::Rect& content_bounds_in_screen_dips) override;
void OnWindowFullscreenTransitionStart(bool target_fullscreen_state) override;
void OnWindowFullscreenTransitionComplete(
bool target_fullscreen_state) 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;
...@@ -157,6 +171,9 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl ...@@ -157,6 +171,9 @@ 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 target_fullscreen_state_ = false;
bool in_fullscreen_transition_ = false;
gfx::Rect window_bounds_before_fullscreen_;
std::unique_ptr<ui::RecyclableCompositorMac> compositor_; std::unique_ptr<ui::RecyclableCompositorMac> compositor_;
......
...@@ -89,6 +89,16 @@ gfx::Vector2d BridgedNativeWidgetHostImpl::GetBoundsOffsetForParent() const { ...@@ -89,6 +89,16 @@ gfx::Vector2d BridgedNativeWidgetHostImpl::GetBoundsOffsetForParent() const {
return offset; return offset;
} }
void BridgedNativeWidgetHostImpl::SetFullscreen(bool fullscreen) {
// Note that when the NSWindow begins a fullscreen transition, the value of
// |target_fullscreen_state_| updates via OnWindowFullscreenTransitionStart.
// The update here is necessary for the case where we are currently in
// transition (and therefore OnWindowFullscreenTransitionStart will not be
// called until the current transition completes).
target_fullscreen_state_ = fullscreen;
bridge()->SetFullscreen(target_fullscreen_state_);
}
void BridgedNativeWidgetHostImpl::SetRootView(views::View* root_view) { void BridgedNativeWidgetHostImpl::SetRootView(views::View* root_view) {
root_view_ = root_view; root_view_ = root_view;
// TODO(ccameron): The BridgedNativeWidget should not need to know its root // TODO(ccameron): The BridgedNativeWidget should not need to know its root
...@@ -185,6 +195,12 @@ ui::InputMethod* BridgedNativeWidgetHostImpl::GetInputMethod() { ...@@ -185,6 +195,12 @@ ui::InputMethod* BridgedNativeWidgetHostImpl::GetInputMethod() {
return input_method_.get(); return input_method_.get();
} }
gfx::Rect BridgedNativeWidgetHostImpl::GetRestoredBounds() const {
if (target_fullscreen_state_ || in_fullscreen_transition_)
return window_bounds_before_fullscreen_;
return window_bounds_in_screen_;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// BridgedNativeWidgetHostImpl, views::BridgedNativeWidgetHost: // BridgedNativeWidgetHostImpl, views::BridgedNativeWidgetHost:
...@@ -318,6 +334,27 @@ void BridgedNativeWidgetHostImpl::OnWindowGeometryChanged( ...@@ -318,6 +334,27 @@ void BridgedNativeWidgetHostImpl::OnWindowGeometryChanged(
} }
} }
void BridgedNativeWidgetHostImpl::OnWindowFullscreenTransitionStart(
bool target_fullscreen_state) {
target_fullscreen_state_ = target_fullscreen_state;
in_fullscreen_transition_ = true;
// If going into fullscreen, store an answer for GetRestoredBounds().
if (target_fullscreen_state)
window_bounds_before_fullscreen_ = window_bounds_in_screen_;
// Notify that fullscreen state changed.
native_widget_mac_->OnWindowFullscreenStateChange();
}
void BridgedNativeWidgetHostImpl::OnWindowFullscreenTransitionComplete(
bool actual_fullscreen_state) {
in_fullscreen_transition_ = false;
// Ensure constraints are re-applied when completing a transition.
native_widget_mac_->OnSizeConstraintsChanged();
}
void BridgedNativeWidgetHostImpl::OnWindowDisplayChanged( void BridgedNativeWidgetHostImpl::OnWindowDisplayChanged(
const display::Display& new_display) { const display::Display& new_display) {
bool scale_factor_changed = bool scale_factor_changed =
......
...@@ -320,7 +320,7 @@ gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const { ...@@ -320,7 +320,7 @@ gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const {
} }
gfx::Rect NativeWidgetMac::GetRestoredBounds() const { gfx::Rect NativeWidgetMac::GetRestoredBounds() const {
return bridge() ? bridge()->GetRestoredBounds() : gfx::Rect(); return bridge_host_ ? bridge_host_->GetRestoredBounds() : gfx::Rect();
} }
std::string NativeWidgetMac::GetWorkspace() const { std::string NativeWidgetMac::GetWorkspace() const {
...@@ -531,14 +531,13 @@ void NativeWidgetMac::Restore() { ...@@ -531,14 +531,13 @@ void NativeWidgetMac::Restore() {
} }
void NativeWidgetMac::SetFullscreen(bool fullscreen) { void NativeWidgetMac::SetFullscreen(bool fullscreen) {
if (!bridge() || fullscreen == IsFullscreen()) if (!bridge_host_)
return; return;
bridge_host_->SetFullscreen(fullscreen);
bridge()->ToggleDesiredFullscreenState();
} }
bool NativeWidgetMac::IsFullscreen() const { bool NativeWidgetMac::IsFullscreen() const {
return bridge() && bridge()->target_fullscreen_state(); return bridge_host_ && bridge_host_->target_fullscreen_state();
} }
void NativeWidgetMac::SetOpacity(float opacity) { void NativeWidgetMac::SetOpacity(float opacity) {
...@@ -640,7 +639,11 @@ bool NativeWidgetMac::IsTranslucentWindowOpacitySupported() const { ...@@ -640,7 +639,11 @@ bool NativeWidgetMac::IsTranslucentWindowOpacitySupported() const {
} }
void NativeWidgetMac::OnSizeConstraintsChanged() { void NativeWidgetMac::OnSizeConstraintsChanged() {
bridge()->OnSizeConstraintsChanged(); Widget* widget = GetWidget();
bridge()->SetSizeConstraints(widget->GetMinimumSize(),
widget->GetMaximumSize(),
widget->widget_delegate()->CanResize(),
widget->widget_delegate()->CanMaximize());
} }
void NativeWidgetMac::RepostNativeEvent(gfx::NativeEvent native_event) { void NativeWidgetMac::RepostNativeEvent(gfx::NativeEvent native_event) {
......
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