Skip to content

Commit

Permalink
Removes WmWindow from ash/wm/root_window_finder.h, ash/wm/workspace/p…
Browse files Browse the repository at this point in the history
…hantom_window_controller.h and

connected code.

BUG=722553
TEST=None (refactoring)

Review-Url: https://codereview.chromium.org/2900423002
Cr-Commit-Position: refs/heads/master@{#474672}
  • Loading branch information
varkha authored and Commit bot committed May 25, 2017
1 parent 6483de8 commit 3c60fc5
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 114 deletions.
10 changes: 3 additions & 7 deletions ash/autoclick/autoclick_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/shell.h"
#include "ash/wm/root_window_finder.h"
#include "ash/wm_window.h"
#include "base/timer/timer.h"
#include "ui/aura/window_observer.h"
#include "ui/aura/window_tree_host.h"
Expand Down Expand Up @@ -138,8 +137,7 @@ void AutoclickControllerImpl::OnScrollEvent(ui::ScrollEvent* event) {

views::Widget* AutoclickControllerImpl::CreateAutoclickRingWidget(
const gfx::Point& event_location) {
aura::Window* target =
WmWindow::GetAuraWindow(ash::wm::GetRootWindowAt(event_location));
aura::Window* target = ash::wm::GetRootWindowAt(event_location);
SetTapDownTarget(target);
aura::Window* root_window = target->GetRootWindow();
widget_.reset(new views::Widget);
Expand All @@ -160,8 +158,7 @@ views::Widget* AutoclickControllerImpl::CreateAutoclickRingWidget(
void AutoclickControllerImpl::UpdateAutoclickRingWidget(
views::Widget* widget,
const gfx::Point& event_location) {
aura::Window* target =
WmWindow::GetAuraWindow(ash::wm::GetRootWindowAt(event_location));
aura::Window* target = ash::wm::GetRootWindowAt(event_location);
SetTapDownTarget(target);
aura::Window* root_window = target->GetRootWindow();
if (widget->GetNativeView()->GetRootWindow() != root_window) {
Expand All @@ -173,8 +170,7 @@ void AutoclickControllerImpl::UpdateAutoclickRingWidget(

void AutoclickControllerImpl::DoAutoclick(const gfx::Point& event_location,
const int mouse_event_flags) {
aura::Window* root_window =
WmWindow::GetAuraWindow(wm::GetRootWindowAt(event_location));
aura::Window* root_window = wm::GetRootWindowAt(event_location);
DCHECK(root_window) << "Root window not found while attempting autoclick.";

gfx::Point click_location(event_location);
Expand Down
5 changes: 2 additions & 3 deletions ash/display/screen_ash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/wm/root_window_finder.h"
#include "ash/wm_window.h"
#include "base/logging.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/display/display.h"
#include "ui/display/display_finder.h"
Expand Down Expand Up @@ -95,8 +95,7 @@ bool ScreenAsh::IsWindowUnderCursor(gfx::NativeWindow window) {
}

gfx::NativeWindow ScreenAsh::GetWindowAtScreenPoint(const gfx::Point& point) {
aura::Window* root_window =
WmWindow::GetAuraWindow(wm::GetRootWindowAt(point));
aura::Window* root_window = wm::GetRootWindowAt(point);
aura::client::ScreenPositionClient* position_client =
aura::client::GetScreenPositionClient(root_window);

Expand Down
11 changes: 4 additions & 7 deletions ash/drag_drop/drag_drop_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/shell.h"
#include "ash/wm/root_window_finder.h"
#include "ash/wm_window.h"
#include "ui/aura/client/window_parenting_client.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
Expand Down Expand Up @@ -69,8 +68,7 @@ aura::Window* DragDropTracker::GetTarget(const ui::LocatedEvent& event) {
DCHECK(capture_window_.get());
gfx::Point location_in_screen = event.location();
::wm::ConvertPointToScreen(capture_window_.get(), &location_in_screen);
aura::Window* root_window_at_point =
WmWindow::GetAuraWindow(wm::GetRootWindowAt(location_in_screen));
aura::Window* root_window_at_point = wm::GetRootWindowAt(location_in_screen);
gfx::Point location_in_root = location_in_screen;
::wm::ConvertPointFromScreen(root_window_at_point, &location_in_root);
return root_window_at_point->GetEventHandlerForPoint(location_in_root);
Expand All @@ -85,10 +83,9 @@ ui::LocatedEvent* DragDropTracker::ConvertEvent(aura::Window* target,
gfx::Point location_in_screen = event.location();
::wm::ConvertPointToScreen(capture_window_.get(), &location_in_screen);
gfx::Point target_root_location = event.root_location();
aura::Window::ConvertPointToTarget(
capture_window_->GetRootWindow(),
WmWindow::GetAuraWindow(wm::GetRootWindowAt(location_in_screen)),
&target_root_location);
aura::Window::ConvertPointToTarget(capture_window_->GetRootWindow(),
wm::GetRootWindowAt(location_in_screen),
&target_root_location);
return new ui::MouseEvent(
event.type(), target_location, target_root_location,
ui::EventTimeForNow(), event.flags(),
Expand Down
60 changes: 25 additions & 35 deletions ash/extended_desktop_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "ash/wm/root_window_finder.h"
#include "ash/wm/window_properties.h"
#include "ash/wm/window_util.h"
#include "ash/wm_window.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/aura/client/capture_client.h"
Expand Down Expand Up @@ -291,24 +290,17 @@ TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
SetSecondaryDisplayLayout(display::DisplayPlacement::LEFT);
aura::Window::Windows root_windows = Shell::GetAllRootWindows();

EXPECT_EQ(root_windows[1], WmWindow::GetAuraWindow(
wm::GetRootWindowAt(gfx::Point(-400, 100))));
EXPECT_EQ(root_windows[1],
WmWindow::GetAuraWindow(wm::GetRootWindowAt(gfx::Point(-1, 100))));
EXPECT_EQ(root_windows[0],
WmWindow::GetAuraWindow(wm::GetRootWindowAt(gfx::Point(0, 300))));
EXPECT_EQ(root_windows[0],
WmWindow::GetAuraWindow(wm::GetRootWindowAt(gfx::Point(700, 300))));
EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-400, 100)));
EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-1, 100)));
EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 300)));
EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(700, 300)));

// Zero origin.
EXPECT_EQ(root_windows[0],
WmWindow::GetAuraWindow(wm::GetRootWindowAt(gfx::Point(0, 0))));
EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0)));

// Out of range point should return the nearest root window
EXPECT_EQ(root_windows[1],
WmWindow::GetAuraWindow(wm::GetRootWindowAt(gfx::Point(-600, 0))));
EXPECT_EQ(root_windows[0],
WmWindow::GetAuraWindow(wm::GetRootWindowAt(gfx::Point(701, 100))));
EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-600, 0)));
EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100)));
}

TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
Expand All @@ -318,34 +310,32 @@ TEST_F(ExtendedDesktopTest, GetRootWindowMatching) {
aura::Window::Windows root_windows = Shell::GetAllRootWindows();

// Containing rect.
EXPECT_EQ(root_windows[1], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
gfx::Rect(-300, 10, 50, 50))));
EXPECT_EQ(root_windows[0], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
gfx::Rect(100, 10, 50, 50))));
EXPECT_EQ(root_windows[1],
wm::GetRootWindowMatching(gfx::Rect(-300, 10, 50, 50)));
EXPECT_EQ(root_windows[0],
wm::GetRootWindowMatching(gfx::Rect(100, 10, 50, 50)));

// Intersecting rect.
EXPECT_EQ(root_windows[1], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
gfx::Rect(-200, 0, 300, 300))));
EXPECT_EQ(root_windows[0], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
gfx::Rect(-100, 0, 300, 300))));
EXPECT_EQ(root_windows[1],
wm::GetRootWindowMatching(gfx::Rect(-200, 0, 300, 300)));
EXPECT_EQ(root_windows[0],
wm::GetRootWindowMatching(gfx::Rect(-100, 0, 300, 300)));

// Zero origin.
EXPECT_EQ(root_windows[0], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
gfx::Rect(0, 0, 0, 0))));
EXPECT_EQ(root_windows[0], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
gfx::Rect(0, 0, 1, 1))));
EXPECT_EQ(root_windows[0], wm::GetRootWindowMatching(gfx::Rect(0, 0, 0, 0)));
EXPECT_EQ(root_windows[0], wm::GetRootWindowMatching(gfx::Rect(0, 0, 1, 1)));

// Empty rect.
EXPECT_EQ(root_windows[1], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
gfx::Rect(-400, 100, 0, 0))));
EXPECT_EQ(root_windows[0], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
gfx::Rect(100, 100, 0, 0))));
EXPECT_EQ(root_windows[1],
wm::GetRootWindowMatching(gfx::Rect(-400, 100, 0, 0)));
EXPECT_EQ(root_windows[0],
wm::GetRootWindowMatching(gfx::Rect(100, 100, 0, 0)));

// Out of range rect should return the primary root window.
EXPECT_EQ(root_windows[0], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
gfx::Rect(-600, -300, 50, 50))));
EXPECT_EQ(root_windows[0], WmWindow::GetAuraWindow(wm::GetRootWindowMatching(
gfx::Rect(0, 1000, 50, 50))));
EXPECT_EQ(root_windows[0],
wm::GetRootWindowMatching(gfx::Rect(-600, -300, 50, 50)));
EXPECT_EQ(root_windows[0],
wm::GetRootWindowMatching(gfx::Rect(0, 1000, 50, 50)));
}

TEST_F(ExtendedDesktopTest, Capture) {
Expand Down
8 changes: 3 additions & 5 deletions ash/frame/caption_buttons/frame_size_button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "ash/wm/window_state.h"
#include "ash/wm/wm_event.h"
#include "ash/wm/workspace/phantom_window_controller.h"
#include "ash/wm_window.h"
#include "base/i18n/rtl.h"
#include "ui/aura/window.h"
#include "ui/gfx/geometry/vector2d.h"
Expand Down Expand Up @@ -214,8 +213,7 @@ void FrameSizeButton::UpdateSnapType(const ui::LocatedEvent& event) {
if (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT) {
aura::Window* window = frame_->GetNativeWindow();
if (!phantom_window_controller_.get()) {
phantom_window_controller_.reset(
new PhantomWindowController(WmWindow::Get(window)));
phantom_window_controller_.reset(new PhantomWindowController(window));
}
gfx::Rect phantom_bounds_in_screen =
(snap_type_ == SNAP_LEFT)
Expand Down Expand Up @@ -246,8 +244,8 @@ bool FrameSizeButton::CommitSnap(const ui::LocatedEvent& event) {
UpdateSnapType(event);

if (in_snap_mode_ && (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT)) {
WmWindow* window = WmWindow::Get(frame_->GetNativeWindow());
wm::WindowState* window_state = window->GetWindowState();
wm::WindowState* window_state =
wm::GetWindowState(frame_->GetNativeWindow());
const wm::WMEvent snap_event(snap_type_ == SNAP_LEFT
? wm::WM_EVENT_SNAP_LEFT
: wm::WM_EVENT_SNAP_RIGHT);
Expand Down
4 changes: 1 addition & 3 deletions ash/mus/screen_mus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "ash/mus/screen_mus.h"

#include "ash/wm/root_window_finder.h"
#include "ash/wm_window.h"
#include "services/ui/public/interfaces/display/display_controller.mojom.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/env.h"
Expand Down Expand Up @@ -57,8 +56,7 @@ bool ScreenMus::IsWindowUnderCursor(gfx::NativeWindow window) {
}

gfx::NativeWindow ScreenMus::GetWindowAtScreenPoint(const gfx::Point& point) {
aura::Window* root_window =
WmWindow::GetAuraWindow(wm::GetRootWindowAt(point));
aura::Window* root_window = wm::GetRootWindowAt(point);
aura::client::ScreenPositionClient* position_client =
aura::client::GetScreenPositionClient(root_window);

Expand Down
12 changes: 6 additions & 6 deletions ash/shelf/shelf_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,9 @@ bool ShelfView::StartDrag(const std::string& app_id,
// First we have to center the mouse cursor over the item.
gfx::Point pt = drag_and_drop_view->GetBoundsInScreen().CenterPoint();
views::View::ConvertPointFromScreen(drag_and_drop_view, &pt);
gfx::Point point_in_root =
wm::GetRootWindowAt(location_in_screen_coordinates)
->ConvertPointFromScreen(location_in_screen_coordinates);
gfx::Point point_in_root = location_in_screen_coordinates;
::wm::ConvertPointFromScreen(
wm::GetRootWindowAt(location_in_screen_coordinates), &point_in_root);
ui::MouseEvent event(ui::ET_MOUSE_PRESSED, pt, point_in_root,
ui::EventTimeForNow(), 0, 0);
PointerPressedOnButton(drag_and_drop_view, DRAG_AND_DROP, event);
Expand All @@ -580,9 +580,9 @@ bool ShelfView::Drag(const gfx::Point& location_in_screen_coordinates) {
views::View* drag_and_drop_view =
view_model_->view_at(model_->ItemIndexByID(drag_and_drop_shelf_id_));
ConvertPointFromScreen(drag_and_drop_view, &pt);
gfx::Point point_in_root =
wm::GetRootWindowAt(location_in_screen_coordinates)
->ConvertPointFromScreen(location_in_screen_coordinates);
gfx::Point point_in_root = location_in_screen_coordinates;
::wm::ConvertPointFromScreen(
wm::GetRootWindowAt(location_in_screen_coordinates), &point_in_root);
ui::MouseEvent event(ui::ET_MOUSE_DRAGGED, pt, point_in_root,
ui::EventTimeForNow(), 0, 0);
PointerDraggedOnButton(drag_and_drop_view, DRAG_AND_DROP, event);
Expand Down
6 changes: 3 additions & 3 deletions ash/shell_port.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ void ShellPort::ShowContextMenu(const gfx::Point& location_in_screen,
return;
}

WmWindow* root = wm::GetRootWindowAt(location_in_screen);
root->GetRootWindowController()->ShowContextMenu(location_in_screen,
source_type);
aura::Window* root = wm::GetRootWindowAt(location_in_screen);
RootWindowController::ForWindow(root)->ShowContextMenu(location_in_screen,
source_type);
}

void ShellPort::OnLockStateEvent(LockStateObserver::EventType event) {
Expand Down
4 changes: 1 addition & 3 deletions ash/test/ui_controls_factory_ash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "ash/shell.h"
#include "ash/wm/root_window_finder.h"
#include "ash/wm/window_properties.h"
#include "ash/wm_window.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/env.h"
Expand Down Expand Up @@ -44,8 +43,7 @@ UIControlsAura* GetUIControlsForRootWindow(aura::Window* root_window) {
// Returns the UIControls object for the RootWindow at |point_in_screen|.
UIControlsAura* GetUIControlsAt(const gfx::Point& point_in_screen) {
// TODO(mazda): Support the case passive grab is taken.
return GetUIControlsForRootWindow(
WmWindow::GetAuraWindow(ash::wm::GetRootWindowAt(point_in_screen)));
return GetUIControlsForRootWindow(ash::wm::GetRootWindowAt(point_in_screen));
}

} // namespace
Expand Down
4 changes: 1 addition & 3 deletions ash/wm/container_finder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "ash/wm/always_on_top_controller.h"
#include "ash/wm/root_window_finder.h"
#include "ash/wm/window_state.h"
#include "ash/wm_window.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/gfx/geometry/rect.h"
Expand All @@ -25,8 +24,7 @@ namespace {
aura::Window* FindContainerRoot(const gfx::Rect& bounds) {
if (bounds == gfx::Rect())
return Shell::GetRootWindowForNewWindows();
WmWindow* root = GetRootWindowMatching(bounds);
return root ? root->aura_window() : nullptr;
return GetRootWindowMatching(bounds);
}

bool HasTransientParentWindow(const aura::Window* window) {
Expand Down
12 changes: 7 additions & 5 deletions ash/wm/root_window_finder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/wm_window.h"
#include "ui/aura/window.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/gfx/geometry/point.h"
Expand All @@ -15,21 +15,23 @@
namespace ash {
namespace wm {

WmWindow* GetRootWindowAt(const gfx::Point& point) {
aura::Window* GetRootWindowAt(const gfx::Point& point) {
const display::Display& display =
display::Screen::GetScreen()->GetDisplayNearestPoint(point);
DCHECK(display.is_valid());
RootWindowController* root_window_controller =
Shell::GetRootWindowControllerWithDisplayId(display.id());
return root_window_controller ? root_window_controller->GetWindow() : nullptr;
return root_window_controller ? root_window_controller->GetRootWindow()
: nullptr;
}

WmWindow* GetRootWindowMatching(const gfx::Rect& rect) {
aura::Window* GetRootWindowMatching(const gfx::Rect& rect) {
const display::Display& display =
display::Screen::GetScreen()->GetDisplayMatching(rect);
RootWindowController* root_window_controller =
Shell::GetRootWindowControllerWithDisplayId(display.id());
return root_window_controller ? root_window_controller->GetWindow() : nullptr;
return root_window_controller ? root_window_controller->GetRootWindow()
: nullptr;
}

} // namespace wm
Expand Down
17 changes: 9 additions & 8 deletions ash/wm/root_window_finder.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@

#include "ash/ash_export.h"

namespace aura {
class Window;
} // namespace aura

namespace gfx {
class Point;
class Rect;
} // namespace gfx

namespace ash {

class WmWindow;

namespace wm {

// Returns the RootWindow at |point| in the virtual screen coordinates.
// Returns NULL if the root window does not exist at the given
// point.
ASH_EXPORT WmWindow* GetRootWindowAt(const gfx::Point& point);
// Returns nullptr if the root window does not exist at the given point.
ASH_EXPORT aura::Window* GetRootWindowAt(const gfx::Point& point);

// Returns the RootWindow that shares the most area with |rect| in
// the virtual scren coordinates.
ASH_EXPORT WmWindow* GetRootWindowMatching(const gfx::Rect& rect);
// Returns the RootWindow that shares the most area with |rect| in the virtual
// screen coordinates.
ASH_EXPORT aura::Window* GetRootWindowMatching(const gfx::Rect& rect);

} // namespace wm
} // namespace ash
Expand Down
Loading

0 comments on commit 3c60fc5

Please sign in to comment.