Skip to content

Commit

Permalink
chromeos: gets rid of wm_screen_util
Browse files Browse the repository at this point in the history
And folds implementation back into ash/screen_util.

BUG=671246
TEST=covered by tests
R=msw@chromium.org

Review-Url: https://codereview.chromium.org/2860163005
Cr-Commit-Position: refs/heads/master@{#469687}
  • Loading branch information
sky authored and Commit bot committed May 5, 2017
1 parent bf1b529 commit 00f0b89
Show file tree
Hide file tree
Showing 24 changed files with 140 additions and 171 deletions.
2 changes: 0 additions & 2 deletions ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,6 @@ component("ash") {
"wm/window_util.h",
"wm/wm_event.cc",
"wm/wm_event.h",
"wm/wm_screen_util.cc",
"wm/wm_screen_util.h",
"wm/wm_snap_to_pixel_layout_manager.cc",
"wm/wm_snap_to_pixel_layout_manager.h",
"wm/wm_toplevel_window_event_handler.cc",
Expand Down
4 changes: 2 additions & 2 deletions ash/app_list/app_list_presenter_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "ash/shell.h"
#include "ash/shell_port.h"
#include "ash/wm/maximize_mode/maximize_mode_controller.h"
#include "ash/wm/wm_screen_util.h"
#include "ash/wm_window.h"
#include "base/command_line.h"
#include "ui/app_list/app_list_constants.h"
Expand All @@ -38,7 +37,8 @@ namespace {
// that height (so that the app list never starts above the top of the screen).
gfx::Point GetCenterOfDisplayForWindow(WmWindow* window, int minimum_height) {
DCHECK(window);
gfx::Rect bounds = wm::GetDisplayBoundsWithShelf(window);
gfx::Rect bounds =
ScreenUtil::GetDisplayBoundsWithShelf(window->aura_window());
bounds = window->GetRootWindow()->ConvertRectToScreen(bounds);

// If the virtual keyboard is active, subtract it from the display bounds, so
Expand Down
5 changes: 1 addition & 4 deletions ash/display/window_tree_host_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#include "ash/wm/window_state.h"
#include "ash/wm/window_state_aura.h"
#include "ash/wm/wm_event.h"
#include "ash/wm/wm_screen_util.h"
#include "ash/wm_window.h"
#include "base/command_line.h"
#include "ui/aura/client/focus_change_observer.h"
#include "ui/aura/client/focus_client.h"
Expand Down Expand Up @@ -1494,8 +1492,7 @@ class RootWindowTestObserver : public aura::WindowObserver {
void OnWindowBoundsChanged(aura::Window* window,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) override {
shelf_display_bounds_ =
wm::GetDisplayBoundsWithShelf(WmWindow::Get(window));
shelf_display_bounds_ = ScreenUtil::GetDisplayBoundsWithShelf(window);
}

const gfx::Rect& shelf_display_bounds() const {
Expand Down
1 change: 0 additions & 1 deletion ash/root_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
#include "ash/wm/window_state.h"
#include "ash/wm/window_state_aura.h"
#include "ash/wm/window_util.h"
#include "ash/wm/wm_screen_util.h"
#include "ash/wm/workspace/workspace_layout_manager.h"
#include "ash/wm/workspace_controller.h"
#include "ash/wm_window.h"
Expand Down
17 changes: 15 additions & 2 deletions ash/screen_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ash/root_window_controller.h"
#include "ash/shelf/wm_shelf.h"
#include "ash/shell.h"
#include "ash/shell_port.h"
#include "base/logging.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/window_event_dispatcher.h"
Expand All @@ -23,8 +24,7 @@ gfx::Rect ScreenUtil::GetMaximizedWindowBoundsInParent(aura::Window* window) {
aura::Window* root_window = window->GetRootWindow();
if (GetRootWindowController(root_window)->wm_shelf()->shelf_widget())
return GetDisplayWorkAreaBoundsInParent(window);
else
return GetDisplayBoundsInParent(window);
return GetDisplayBoundsInParent(window);
}

// static
Expand All @@ -43,4 +43,17 @@ gfx::Rect ScreenUtil::GetDisplayWorkAreaBoundsInParent(aura::Window* window) {
return result;
}

// static
gfx::Rect ScreenUtil::GetDisplayBoundsWithShelf(aura::Window* window) {
if (ShellPort::Get()->IsInUnifiedMode()) {
// In unified desktop mode, there is only one shelf in the first display.
gfx::SizeF size(ShellPort::Get()->GetFirstDisplay().size());
float scale = window->GetRootWindow()->bounds().height() / size.height();
size.Scale(scale, scale);
return gfx::Rect(gfx::ToCeiledSize(size));
}

return window->GetRootWindow()->bounds();
}

} // namespace ash
12 changes: 8 additions & 4 deletions ash/screen_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ class ASH_EXPORT ScreenUtil {
// Returns the display's work area bounds in parent coordinates.
static gfx::Rect GetDisplayWorkAreaBoundsInParent(aura::Window* window);

private:
ScreenUtil() {}
~ScreenUtil() {}
// Returns the bounds of the physical display containing the shelf for
// |window|. Physical displays can differ from logical displays in unified
// desktop mode.
// TODO(oshima): Consider using physical displays in window layout, instead of
// root windows, and only use logical display in display management code.
static gfx::Rect GetDisplayBoundsWithShelf(aura::Window* window);

DISALLOW_COPY_AND_ASSIGN(ScreenUtil);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenUtil);
};

} // namespace ash
Expand Down
16 changes: 9 additions & 7 deletions ash/screen_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/window_util.h"
#include "ash/wm/wm_screen_util.h"
#include "ash/wm_window.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
Expand Down Expand Up @@ -113,23 +111,27 @@ TEST_F(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) {

views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
WmWindow* window = WmWindow::Get(widget->GetNativeWindow());
aura::Window* window = widget->GetNativeWindow();

UpdateDisplay("500x400");
EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString());
EXPECT_EQ("0,0 500x400",
ScreenUtil::GetDisplayBoundsWithShelf(window).ToString());

UpdateDisplay("500x400,600x400");
EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString());
EXPECT_EQ("0,0 500x400",
ScreenUtil::GetDisplayBoundsWithShelf(window).ToString());

// Move to the 2nd physical display. Shelf's display still should be
// the first.
widget->SetBounds(gfx::Rect(800, 0, 100, 100));
ASSERT_EQ("800,0 100x100", widget->GetWindowBoundsInScreen().ToString());

EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString());
EXPECT_EQ("0,0 500x400",
ScreenUtil::GetDisplayBoundsWithShelf(window).ToString());

UpdateDisplay("600x500");
EXPECT_EQ("0,0 600x500", wm::GetDisplayBoundsWithShelf(window).ToString());
EXPECT_EQ("0,0 600x500",
ScreenUtil::GetDisplayBoundsWithShelf(window).ToString());
}

} // namespace test
Expand Down
21 changes: 12 additions & 9 deletions ash/shelf/shelf_layout_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ash/keyboard/keyboard_observer_register.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "ash/screen_util.h"
#include "ash/session/session_controller.h"
#include "ash/shelf/shelf_constants.h"
#include "ash/shelf/shelf_layout_manager_observer.h"
Expand All @@ -25,7 +26,6 @@
#include "ash/wm/screen_pinning_controller.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_state_aura.h"
#include "ash/wm/wm_screen_util.h"
#include "ash/wm_window.h"
#include "base/auto_reset.h"
#include "base/command_line.h"
Expand All @@ -43,6 +43,7 @@
#include "ui/keyboard/keyboard_util.h"
#include "ui/views/border.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/coordinate_conversion.h"
#include "ui/wm/public/activation_client.h"

namespace ash {
Expand Down Expand Up @@ -191,8 +192,8 @@ bool ShelfLayoutManager::IsVisible() const {
}

gfx::Rect ShelfLayoutManager::GetIdealBounds() {
WmWindow* shelf_window = WmWindow::Get(shelf_widget_->GetNativeWindow());
gfx::Rect rect(wm::GetDisplayBoundsInParent(shelf_window));
aura::Window* shelf_window = shelf_widget_->GetNativeWindow();
gfx::Rect rect(ScreenUtil::GetDisplayBoundsInParent(shelf_window));
return SelectValueForShelfAlignment(
gfx::Rect(rect.x(), rect.bottom() - kShelfSize, rect.width(), kShelfSize),
gfx::Rect(rect.x(), rect.y(), kShelfSize, rect.height()),
Expand Down Expand Up @@ -671,8 +672,9 @@ void ShelfLayoutManager::CalculateTargetBounds(const State& state,
shelf_size = 0;
}

WmWindow* shelf_window = WmWindow::Get(shelf_widget_->GetNativeWindow());
gfx::Rect available_bounds = wm::GetDisplayBoundsWithShelf(shelf_window);
aura::Window* shelf_window = shelf_widget_->GetNativeWindow();
gfx::Rect available_bounds =
ScreenUtil::GetDisplayBoundsWithShelf(shelf_window);
available_bounds.Inset(0, chromevox_panel_height_, 0, 0);
int shelf_width = PrimaryAxisValue(available_bounds.width(), shelf_size);
int shelf_height = PrimaryAxisValue(shelf_size, available_bounds.height());
Expand Down Expand Up @@ -749,16 +751,17 @@ void ShelfLayoutManager::CalculateTargetBounds(const State& state,
available_bounds.Subtract(target_bounds->shelf_bounds_in_root);
available_bounds.Subtract(keyboard_bounds_);

WmWindow* root = shelf_window->GetRootWindow();
user_work_area_bounds_ = root->ConvertRectToScreen(available_bounds);
aura::Window* root = shelf_window->GetRootWindow();
::wm::ConvertRectToScreen(root, &available_bounds);
user_work_area_bounds_ = available_bounds;
}

void ShelfLayoutManager::UpdateTargetBoundsForGesture(
TargetBounds* target_bounds) const {
CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_);
bool horizontal = wm_shelf_->IsHorizontalAlignment();
WmWindow* window = WmWindow::Get(shelf_widget_->GetNativeWindow());
gfx::Rect available_bounds = wm::GetDisplayBoundsWithShelf(window);
aura::Window* window = shelf_widget_->GetNativeWindow();
gfx::Rect available_bounds = ScreenUtil::GetDisplayBoundsWithShelf(window);
int resistance_free_region = 0;

if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN &&
Expand Down
18 changes: 12 additions & 6 deletions ash/system/toast/toast_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#include "ash/system/toast/toast_manager.h"

#include "ash/public/cpp/config.h"
#include "ash/screen_util.h"
#include "ash/shelf/shelf_constants.h"
#include "ash/shelf/wm_shelf.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/wm_screen_util.h"
#include "ash/wm_window.h"
#include "base/run_loop.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
Expand Down Expand Up @@ -187,7 +188,8 @@ TEST_F(ToastManagerTest, PositionWithVisibleBottomShelf) {
EXPECT_EQ(1, GetToastSerial());

gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow());
gfx::Rect root_bounds =
ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window());

EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds()));
EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
Expand All @@ -212,7 +214,8 @@ TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) {
EXPECT_EQ(1, GetToastSerial());

gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow());
gfx::Rect root_bounds =
ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window());

EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds()));
EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
Expand All @@ -230,7 +233,8 @@ TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) {
EXPECT_EQ(1, GetToastSerial());

gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow());
gfx::Rect root_bounds =
ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window());

EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds()));
EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
Expand All @@ -247,7 +251,8 @@ TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) {

gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
gfx::RectF precise_toast_bounds(toast_bounds);
gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow());
gfx::Rect root_bounds =
ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window());

EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds()));
EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom());
Expand Down Expand Up @@ -275,7 +280,8 @@ TEST_F(ToastManagerTest, PositionWithUnifiedDesktop) {
EXPECT_EQ(1, GetToastSerial());

gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow());
gfx::Rect root_bounds =
ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window());

EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds()));
EXPECT_TRUE(root_bounds.Contains(toast_bounds));
Expand Down
Loading

0 comments on commit 00f0b89

Please sign in to comment.