Commit f053e525 authored by Aga Wronska's avatar Aga Wronska Committed by Commit Bot

Create WorkAreaInsets class

This new component will encapsulate information needed to calculate
work area for root window.
It is in 1:1 relationship with RootWindowController and owned by it.

Caching height on accessibility panel is restored in this change for
consistency with docked magnifier and for performance reasons (avoid
frequent calculation of this value).

Test: manually with 2 displays +  existing unit tests
Bug: 944685
Change-Id: Ib76f144a54408a769ec101e15f6a2f2512aa4ae5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1538689
Commit-Queue: Aga Wronska <agawronska@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644608}
parent 74934b2d
......@@ -1230,6 +1230,8 @@ component("ash") {
"wm/wm_toplevel_window_event_handler.h",
"wm/wm_window_animations.cc",
"wm/wm_window_animations.h",
"wm/work_area_insets.cc",
"wm/work_area_insets.h",
"wm/workspace/backdrop_controller.cc",
"wm/workspace/backdrop_controller.h",
"wm/workspace/backdrop_delegate.h",
......
......@@ -6,6 +6,7 @@
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/wm/work_area_insets.h"
#include "base/logging.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/wm/core/window_util.h"
......@@ -25,12 +26,6 @@ AccessibilityPanelLayoutManager::~AccessibilityPanelLayoutManager() {
display::Screen::GetScreen()->RemoveObserver(this);
}
int AccessibilityPanelLayoutManager::GetPanelHeight() const {
bool has_height = panel_window_ && panel_window_->bounds().y() == 0 &&
panel_state_ == mojom::AccessibilityPanelState::FULL_WIDTH;
return has_height ? panel_window_->bounds().height() : 0;
}
void AccessibilityPanelLayoutManager::SetAlwaysVisible(bool always_visible) {
always_visible_ = always_visible;
UpdateWindowBounds();
......@@ -42,10 +37,7 @@ void AccessibilityPanelLayoutManager::SetPanelBounds(
panel_bounds_ = bounds;
panel_state_ = state;
UpdateWindowBounds();
// TODO(agawronska): Consider routing this through RootWindowController
// (public method or repeating callback).
Shell::Get()->NotifyAccessibilityInsetsChanged(
panel_window_->GetRootWindow());
UpdateWorkAreaForPanelHeight();
}
void AccessibilityPanelLayoutManager::OnWindowAddedToLayout(
......@@ -57,14 +49,13 @@ void AccessibilityPanelLayoutManager::OnWindowAddedToLayout(
void AccessibilityPanelLayoutManager::OnWindowRemovedFromLayout(
aura::Window* child) {
aura::Window* root_window = panel_window_->GetRootWindow();
// NOTE: In browser_tests a second ChromeVoxPanel can be created while the
// first one is closing due to races between loading the extension and
// closing the widget. We only track the latest panel.
if (child == panel_window_)
panel_window_ = nullptr;
Shell::Get()->NotifyAccessibilityInsetsChanged(root_window);
UpdateWorkAreaForPanelHeight();
}
void AccessibilityPanelLayoutManager::OnChildWindowVisibilityChanged(
......@@ -72,8 +63,7 @@ void AccessibilityPanelLayoutManager::OnChildWindowVisibilityChanged(
bool visible) {
if (child == panel_window_ && visible) {
UpdateWindowBounds();
Shell::Get()->NotifyAccessibilityInsetsChanged(
panel_window_->GetRootWindow());
UpdateWorkAreaForPanelHeight();
}
}
......@@ -129,7 +119,8 @@ void AccessibilityPanelLayoutManager::UpdateWindowBounds() {
// Make sure the accessibility panel is always below the Docked Magnifier
// viewport so it shows up and gets magnified.
int magnifier_height = root_controller->GetDockedMagnifierHeight();
int magnifier_height =
root_controller->work_area_insets()->docked_magnifier_height();
if (bounds.y() < magnifier_height)
bounds.Offset(0, magnifier_height);
// Make sure the accessibility panel doesn't go offscreen when the Docked
......@@ -142,4 +133,13 @@ void AccessibilityPanelLayoutManager::UpdateWindowBounds() {
panel_window_->SetBounds(bounds);
}
void AccessibilityPanelLayoutManager::UpdateWorkAreaForPanelHeight() {
bool has_height = panel_window_ && panel_window_->bounds().y() == 0 &&
panel_state_ == mojom::AccessibilityPanelState::FULL_WIDTH;
Shell::GetPrimaryRootWindowController()
->work_area_insets()
->SetAccessibilityPanelHeight(
has_height ? panel_window_->bounds().height() : 0);
}
} // namespace ash
......@@ -37,9 +37,6 @@ class ASH_EXPORT AccessibilityPanelLayoutManager
AccessibilityPanelLayoutManager();
~AccessibilityPanelLayoutManager() override;
// Returns current height of the accessibility panel in DIPs.
int GetPanelHeight() const;
// Controls the panel's visibility and location.
void SetAlwaysVisible(bool always_visible);
void SetPanelBounds(const gfx::Rect& bounds,
......@@ -76,6 +73,9 @@ class ASH_EXPORT AccessibilityPanelLayoutManager
// Updates the panel window bounds.
void UpdateWindowBounds();
// Sets cached height of the accessibility panel.
void UpdateWorkAreaForPanelHeight();
// The panel being managed (e.g. the ChromeVoxPanel's native aura window).
aura::Window* panel_window_ = nullptr;
......
......@@ -16,6 +16,7 @@
#include "ash/shell.h"
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/splitview/split_view_controller.h"
#include "ash/wm/work_area_insets.h"
#include "base/bind.h"
#include "base/numerics/ranges.h"
#include "components/prefs/pref_change_registrar.h"
......@@ -62,7 +63,7 @@ inline gfx::Point GetCursorScreenPoint() {
// given magnifier viewport |height| is allocated at the top of the screen.
void SetViewportHeightInWorkArea(aura::Window* window, int height) {
DCHECK(window);
RootWindowController::ForWindow(window->GetRootWindow())
WorkAreaInsets::ForWindow(window->GetRootWindow())
->SetDockedMagnifierHeight(height);
}
......
......@@ -55,6 +55,7 @@
#include "ash/wm/window_properties.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "ash/wm/work_area_insets.h"
#include "ash/wm/workspace/workspace_layout_manager.h"
#include "ash/wm/workspace_controller.h"
#include "base/bind.h"
......@@ -357,6 +358,7 @@ std::vector<RootWindowController*>*
RootWindowController::~RootWindowController() {
Shutdown();
DCHECK(!wallpaper_widget_controller_.get());
work_area_insets_.reset();
ash_host_.reset();
mus_window_tree_host_.reset();
// The CaptureClient needs to be around for as long as the RootWindow is
......@@ -512,21 +514,6 @@ gfx::Point RootWindowController::GetLastMouseLocationInRoot() {
return window_tree_host_->dispatcher()->GetLastMouseLocationInRoot();
}
int RootWindowController::GetAccessibilityPanelHeight() const {
const AccessibilityPanelLayoutManager* layout_manager =
GetAccessibilityPanelLayoutManager();
return layout_manager ? layout_manager->GetPanelHeight() : 0;
}
int RootWindowController::GetDockedMagnifierHeight() const {
return docked_magnifier_height_;
}
void RootWindowController::SetDockedMagnifierHeight(int height) {
docked_magnifier_height_ = height;
Shell::Get()->NotifyAccessibilityInsetsChanged(GetRootWindow());
}
aura::Window* RootWindowController::GetContainer(int container_id) {
return GetRootWindow()->GetChildById(container_id);
}
......@@ -705,7 +692,8 @@ RootWindowController::RootWindowController(
: window_tree_host),
shelf_(std::make_unique<Shelf>()),
lock_screen_action_background_controller_(
LockScreenActionBackgroundController::Create()) {
LockScreenActionBackgroundController::Create()),
work_area_insets_(std::make_unique<WorkAreaInsets>(this)) {
DCHECK((ash_host && !window_tree_host) || (!ash_host && window_tree_host));
if (!root_window_controllers_)
......
......@@ -53,6 +53,7 @@ class TouchExplorationManager;
class TouchObserverHUD;
class WallpaperWidgetController;
class WindowManager;
class WorkAreaInsets;
class WorkspaceController;
namespace wm {
......@@ -119,6 +120,9 @@ class ASH_EXPORT RootWindowController {
return root_window_layout_manager_;
}
// Returns parameters of the work area associated with this root window.
WorkAreaInsets* work_area_insets() { return work_area_insets_.get(); }
// Access the shelf layout manager associated with this root
// window controller, NULL if no such shelf exists.
ShelfLayoutManager* GetShelfLayoutManager();
......@@ -157,16 +161,6 @@ class ASH_EXPORT RootWindowController {
// coordinates. This may return a point outside the root window's bounds.
gfx::Point GetLastMouseLocationInRoot();
// Returns height of the accessibility panel for this root window.
int GetAccessibilityPanelHeight() const;
// Returns height of the docked magnifier for this root window.
int GetDockedMagnifierHeight() const;
// Sets height of the docked magnifier for this root window. Notifies shell
// observers that work area changed.
void SetDockedMagnifierHeight(int height);
aura::Window* GetContainer(int container_id);
const aura::Window* GetContainer(int container_id) const;
......@@ -310,7 +304,7 @@ class ASH_EXPORT RootWindowController {
// calling related cleanup code more than once.
bool did_close_child_windows_ = false;
int docked_magnifier_height_ = 0;
std::unique_ptr<WorkAreaInsets> work_area_insets_;
static std::vector<RootWindowController*>* root_window_controllers_;
......
......@@ -8,9 +8,9 @@
#include "ash/display/mirror_window_controller.h"
#include "ash/display/window_tree_host_manager.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/wm/work_area_insets.h"
#include "base/logging.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/window_event_dispatcher.h"
......@@ -40,11 +40,11 @@ gfx::Rect GetDisplayBoundsInParent(aura::Window* window) {
gfx::Rect GetFullscreenWindowBoundsInParent(aura::Window* window) {
gfx::Rect result = GetDisplayBoundsInParent(window);
const RootWindowController* const root_window_controller =
RootWindowController::ForWindow(window->GetRootWindow());
const WorkAreaInsets* const work_area_insets =
WorkAreaInsets::ForWindow(window->GetRootWindow());
result.Inset(0,
root_window_controller->GetAccessibilityPanelHeight() +
root_window_controller->GetDockedMagnifierHeight(),
work_area_insets->accessibility_panel_height() +
work_area_insets->docked_magnifier_height(),
0, 0);
return result;
}
......
......@@ -37,6 +37,7 @@
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "ash/wm/work_area_insets.h"
#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/i18n/rtl.h"
......@@ -913,12 +914,13 @@ gfx::Rect ShelfLayoutManager::CalculateTargetBounds(
}
aura::Window* shelf_window = shelf_widget_->GetNativeWindow();
const RootWindowController* root_window_controller =
RootWindowController::ForWindow(shelf_window->GetRootWindow());
const WorkAreaInsets* const work_area_insets =
WorkAreaInsets::ForWindow(shelf_window);
const int accessibility_panel_height =
root_window_controller->GetAccessibilityPanelHeight();
work_area_insets->accessibility_panel_height();
const int docked_magnifier_height =
root_window_controller->GetDockedMagnifierHeight();
work_area_insets->docked_magnifier_height();
gfx::Rect available_bounds =
screen_util::GetDisplayBoundsWithShelf(shelf_window);
available_bounds.Inset(
......
......@@ -8,7 +8,6 @@
#include <utility>
#include "ash/public/cpp/window_animation_types.h"
#include "ash/root_window_controller.h"
#include "ash/screen_util.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
......@@ -17,6 +16,7 @@
#include "ash/wm/window_state_delegate.h"
#include "ash/wm/window_state_util.h"
#include "ash/wm/wm_event.h"
#include "ash/wm/work_area_insets.h"
#include "ui/aura/window.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/keyboard/keyboard_controller.h"
......@@ -190,8 +190,8 @@ gfx::Rect LockWindowState::GetWindowBounds(aura::Window* window) {
: 0;
gfx::Rect bounds = screen_util::GetDisplayBoundsWithShelf(window);
bounds.Inset(0,
RootWindowController::ForWindow(window->GetRootWindow())
->GetAccessibilityPanelHeight(),
WorkAreaInsets::ForWindow(window->GetRootWindow())
->accessibility_panel_height(),
0, keyboard_height);
return bounds;
}
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/wm/work_area_insets.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ui/aura/window.h"
namespace ash {
// static
WorkAreaInsets* WorkAreaInsets::ForWindow(const aura::Window* window) {
return RootWindowController::ForWindow(window)->work_area_insets();
}
WorkAreaInsets::WorkAreaInsets(RootWindowController* root_window_controller)
: root_window_controller_(root_window_controller) {}
WorkAreaInsets::~WorkAreaInsets() = default;
void WorkAreaInsets::SetDockedMagnifierHeight(int height) {
docked_magnifier_height_ = height;
Shell::Get()->NotifyAccessibilityInsetsChanged(
root_window_controller_->GetRootWindow());
}
void WorkAreaInsets::SetAccessibilityPanelHeight(int height) {
accessibility_panel_height_ = height;
Shell::Get()->NotifyAccessibilityInsetsChanged(
root_window_controller_->GetRootWindow());
}
} // namespace ash
\ No newline at end of file
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_WM_WORK_AREA_INSETS_H_
#define ASH_WM_WORK_AREA_INSETS_H_
#include "ash/ash_export.h"
#include "base/macros.h"
namespace aura {
class Window;
}
namespace ash {
class RootWindowController;
// Insets of the work area associated with this root window.
class ASH_EXPORT WorkAreaInsets {
public:
// Returns work area parameters associated with the given |window|.
static WorkAreaInsets* ForWindow(const aura::Window* window);
explicit WorkAreaInsets(RootWindowController* root_window_controller);
~WorkAreaInsets();
// Returns cached height of the accessibility panel in DIPs for this root
// window.
int accessibility_panel_height() const { return accessibility_panel_height_; }
// Returns cached height of the docked magnifier in DIPs for this root
// window.
int docked_magnifier_height() const { return docked_magnifier_height_; }
// Sets height of the accessibility panel in DIPs for this root window.
// Shell observers will be notified that accessibility insets changed.
void SetDockedMagnifierHeight(int height);
// Sets height of the docked magnifier in DIPs for this root window.
// Shell observers will be notified that accessibility insets changed.
void SetAccessibilityPanelHeight(int height);
private:
// RootWindowController associated with this work area.
RootWindowController* const root_window_controller_ = nullptr;
// Cached height of the docked magnifier in DIPs at the top of the screen.
// It needs to be removed from the available work area.
int docked_magnifier_height_ = 0;
// Cached height of the accessibility panel in DIPs at the top of the
// screen. It needs to be removed from the available work area.
int accessibility_panel_height_ = 0;
DISALLOW_COPY_AND_ASSIGN(WorkAreaInsets);
};
} // namespace ash
#endif // ASH_WM_WORK_AREA_INSETS_H_
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