Commit 9c852c98 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

OopAsh: make Ash share the bounds of the caption buttons with clients.

This avoids some recalculations (chances for bugs) in
BrowserNonClientFrameViewAsh. The bounds are horizontally inverted
(i.e. they are relative to the top right of the frame) to minimize
the number of times they need to be updated when resizing the window
and the likelihood of ephemeral inconsistencies.

Also fix the registered type of kRestoreBoundsOverrideKey. Since it was
registered as a primitive, the address itself would get copied across
processes.

Bug: 854704
Change-Id: Iedd4eb4dfb2172f7a9ba66bbc542db33633aaf77
Reviewed-on: https://chromium-review.googlesource.com/1144058Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577604}
parent ca3a0cec
......@@ -229,6 +229,19 @@ void FrameHeader::LayoutHeaderInternal() {
caption_button_container()->Layout();
// Update clients on the bounds of the caption button only if the bounds have
// changed.
const gfx::Rect* old_bounds_value =
target_widget()->GetNativeWindow()->GetProperty(
ash::kCaptionButtonBoundsKey);
// The bounds are relative to the top right, rather than the normal top left.
gfx::Rect new_bounds_value =
caption_button_container()->bounds() - gfx::Vector2d(view_->width(), 0);
if (!old_bounds_value || new_bounds_value != *old_bounds_value) {
target_widget()->GetNativeWindow()->SetProperty(
ash::kCaptionButtonBoundsKey, new gfx::Rect(new_bounds_value));
}
int origin = 0;
if (back_button_) {
gfx::Size size = back_button_->GetPreferredSize();
......
......@@ -39,6 +39,8 @@ void RegisterWindowProperties(aura::PropertyConverter* property_converter) {
property_converter->RegisterPrimitiveProperty(
kCanConsumeSystemKeysKey, mojom::kCanConsumeSystemKeys_Property,
aura::PropertyConverter::CreateAcceptAnyValueCallback());
property_converter->RegisterRectProperty(
kCaptionButtonBoundsKey, mojom::kCaptionButtonBounds_Property);
property_converter->RegisterPrimitiveProperty(
kFrameBackButtonStateKey,
ui::mojom::WindowManager::kFrameBackButtonState_Property,
......@@ -89,9 +91,8 @@ void RegisterWindowProperties(aura::PropertyConverter* property_converter) {
aura::PropertyConverter::CreateAcceptAnyValueCallback());
property_converter->RegisterStringProperty(
kShelfIDKey, ui::mojom::WindowManager::kShelfID_Property);
property_converter->RegisterPrimitiveProperty(
kRestoreBoundsOverrideKey, mojom::kRestoreBoundsOverride_Property,
aura::PropertyConverter::CreateAcceptAnyValueCallback());
property_converter->RegisterRectProperty(
kRestoreBoundsOverrideKey, mojom::kRestoreBoundsOverride_Property);
property_converter->RegisterPrimitiveProperty(
kRestoreWindowStateTypeOverrideKey,
mojom::kRestoreWindowStateTypeOverride_Property,
......@@ -108,6 +109,7 @@ DEFINE_UI_CLASS_PROPERTY_KEY(BackdropWindowMode,
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kBlockedForAssistantSnapshotKey, false);
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kCanAttachToAnotherWindowKey, true);
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kCanConsumeSystemKeysKey, false);
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect, kCaptionButtonBoundsKey, nullptr);
DEFINE_UI_CLASS_PROPERTY_KEY(FrameBackButtonState,
kFrameBackButtonStateKey,
FrameBackButtonState::kNone);
......
......@@ -76,6 +76,12 @@ ASH_PUBLIC_EXPORT extern const aura::WindowProperty<bool>* const
ASH_PUBLIC_EXPORT extern const aura::WindowProperty<bool>* const
kCanConsumeSystemKeysKey;
// The bounds of the window control button container (min/max/restore) relative
// to the window's frame.
ASH_PUBLIC_EXPORT extern const aura::WindowProperty<gfx::Rect*>* const
kCaptionButtonBoundsKey;
// The state of the frame back button, whether it's visible and enabled.
ASH_PUBLIC_EXPORT extern const aura::WindowProperty<FrameBackButtonState>* const
kFrameBackButtonStateKey;
......
......@@ -14,6 +14,10 @@ const string kBlockedForAssistantSnapshot_Property =
const string kCanConsumeSystemKeys_Property =
"ash:can-consume-system-keys";
// The bounds of the window control buttons (minimize, maximize, restore)
// relative to the frame.
const string kCaptionButtonBounds_Property = "ash:caption-button-bounds";
// An UnguessableToken used to tell Mash the frame image to use for a custom
// Browser theme, for both a window's active state and its inactive state.
// The token to image mapping is stored in ash::ClientImageRegistry.
......
......@@ -549,17 +549,19 @@ void BrowserNonClientFrameViewAsh::Layout() {
LayoutIncognitoButton();
if (hosted_app_extras_container_) {
// TODO(estade): can Ash tell us the bounds of the caption buttons so
// Chrome doesn't have to re-calculate them?
gfx::Size hosted_app_size =
hosted_app_extras_container_->GetPreferredSize();
gfx::Size caption_button_size =
GetAshLayoutSize(ash::AshLayoutSize::kNonBrowserCaption);
hosted_app_extras_container_->SetBounds(
width() -
(GetControlButtonSpacing() + caption_button_size.width()) * 3 -
hosted_app_size.width(),
0, hosted_app_size.width(), caption_button_size.height());
const gfx::Rect* inverted_caption_button_bounds =
frame()->GetNativeWindow()->GetRootWindow()->GetProperty(
ash::kCaptionButtonBoundsKey);
if (inverted_caption_button_bounds) {
gfx::Rect caption_button_bounds =
*inverted_caption_button_bounds + gfx::Vector2d(width(), 0);
gfx::Size hosted_app_size =
hosted_app_extras_container_->GetPreferredSize();
hosted_app_extras_container_->SetBounds(
caption_button_bounds.x() - hosted_app_size.width(),
caption_button_bounds.y(), hosted_app_size.width(),
caption_button_bounds.height());
}
}
BrowserNonClientFrameView::Layout();
......@@ -910,6 +912,8 @@ AvatarButtonStyle BrowserNonClientFrameViewAsh::GetAvatarButtonStyle() const {
// BrowserNonClientFrameViewAsh, private:
bool BrowserNonClientFrameViewAsh::ShouldShowCaptionButtons() const {
DCHECK(!IsMash());
// In tablet mode, to prevent accidental taps of the window controls, and to
// give more horizontal space for tabs and the new tab button especially in
// splitscreen view, we hide the window controls. We only do this when the
......
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