Skip to content

Commit

Permalink
Make GetRootWindow() return a Window instead of a RootWindow.
Browse files Browse the repository at this point in the history
Also adds a typedef from RootWindow to WindowEventDispatcher, the eventual name of this type.
Adds a GetDispatcher() method that crawls up to the root Window and returns the WindowEventDispatcher.

R=sky@chromium.org
http://crbug.com/308843

Review URL: https://codereview.chromium.org/37733003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231077 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
ben@chromium.org committed Oct 25, 2013
1 parent fef72c1 commit bf9cdb3
Show file tree
Hide file tree
Showing 222 changed files with 894 additions and 855 deletions.
2 changes: 1 addition & 1 deletion ash/accelerators/accelerator_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ bool HandleRotateScreen() {
}

bool HandleToggleRootWindowFullScreen() {
Shell::GetPrimaryRootWindow()->ToggleFullScreen();
Shell::GetPrimaryRootWindow()->GetDispatcher()->ToggleFullScreen();
return true;
}

Expand Down
26 changes: 14 additions & 12 deletions ash/accelerators/accelerator_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -603,42 +603,44 @@ TEST_F(AcceleratorControllerTest, ProcessOnce) {
GetController()->Register(accelerator_a, &target);

// The accelerator is processed only once.
aura::WindowEventDispatcher* dispatcher =
Shell::GetPrimaryRootWindow()->GetDispatcher();
#if defined(OS_WIN)
MSG msg1 = { NULL, WM_KEYDOWN, ui::VKEY_A, 0 };
ui::TranslatedKeyEvent key_event1(msg1, false);
EXPECT_TRUE(Shell::GetPrimaryRootWindow()->AsRootWindowHostDelegate()->
OnHostKeyEvent(&key_event1));
EXPECT_TRUE(dispatcher->AsRootWindowHostDelegate()->OnHostKeyEvent(
&key_event1));

MSG msg2 = { NULL, WM_CHAR, L'A', 0 };
ui::TranslatedKeyEvent key_event2(msg2, true);
EXPECT_FALSE(Shell::GetPrimaryRootWindow()->AsRootWindowHostDelegate()->
OnHostKeyEvent(&key_event2));
EXPECT_FALSE(dispatcher->AsRootWindowHostDelegate()->OnHostKeyEvent(
&key_event2));

MSG msg3 = { NULL, WM_KEYUP, ui::VKEY_A, 0 };
ui::TranslatedKeyEvent key_event3(msg3, false);
EXPECT_FALSE(Shell::GetPrimaryRootWindow()->AsRootWindowHostDelegate()->
OnHostKeyEvent(&key_event3));
EXPECT_FALSE(dispatcher->AsRootWindowHostDelegate()->OnHostKeyEvent(
&key_event3));
#elif defined(USE_X11)
XEvent key_event;
ui::InitXKeyEventForTesting(ui::ET_KEY_PRESSED,
ui::VKEY_A,
0,
&key_event);
ui::TranslatedKeyEvent key_event1(&key_event, false);
EXPECT_TRUE(Shell::GetPrimaryRootWindow()->AsRootWindowHostDelegate()->
OnHostKeyEvent(&key_event1));
EXPECT_TRUE(dispatcher->AsRootWindowHostDelegate()->OnHostKeyEvent(
&key_event1));

ui::TranslatedKeyEvent key_event2(&key_event, true);
EXPECT_FALSE(Shell::GetPrimaryRootWindow()->AsRootWindowHostDelegate()->
OnHostKeyEvent(&key_event2));
EXPECT_FALSE(dispatcher->AsRootWindowHostDelegate()->OnHostKeyEvent(
&key_event2));

ui::InitXKeyEventForTesting(ui::ET_KEY_RELEASED,
ui::VKEY_A,
0,
&key_event);
ui::TranslatedKeyEvent key_event3(&key_event, false);
EXPECT_FALSE(Shell::GetPrimaryRootWindow()->AsRootWindowHostDelegate()->
OnHostKeyEvent(&key_event3));
EXPECT_FALSE(dispatcher->AsRootWindowHostDelegate()->OnHostKeyEvent(
&key_event3));
#endif
EXPECT_EQ(1, target.accelerator_pressed_count());
}
Expand Down
4 changes: 2 additions & 2 deletions ash/accelerators/exit_warning_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "grit/ash_strings.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
Expand Down Expand Up @@ -165,7 +165,7 @@ void ExitWarningHandler::CancelTimer() {
void ExitWarningHandler::Show() {
if (widget_)
return;
aura::RootWindow* root_window = Shell::GetTargetRootWindow();
aura::Window* root_window = Shell::GetTargetRootWindow();
ExitWarningWidgetDelegateView* delegate = new ExitWarningWidgetDelegateView;
gfx::Size rs = root_window->bounds().size();
gfx::Size ps = delegate->GetPreferredSize();
Expand Down
14 changes: 8 additions & 6 deletions ash/accelerators/nested_dispatcher_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,18 @@ void DispatchKeyReleaseA() {
ui::VKEY_A,
0,
&native_event);
ash::Shell::GetPrimaryRootWindow()->PostNativeEvent(&native_event);
aura::WindowEventDispatcher* dispatcher =
ash::Shell::GetPrimaryRootWindow()->GetDispatcher();
dispatcher->PostNativeEvent(&native_event);
ui::InitXKeyEventForTesting(ui::ET_KEY_RELEASED,
ui::VKEY_A,
0,
&native_event);
ash::Shell::GetPrimaryRootWindow()->PostNativeEvent(&native_event);
dispatcher->PostNativeEvent(&native_event);
#endif

// Send noop event to signal dispatcher to exit.
ash::Shell::GetPrimaryRootWindow()->PostNativeEvent(ui::CreateNoopEvent());
dispatcher->PostNativeEvent(ui::CreateNoopEvent());
}

} // namespace
Expand All @@ -111,7 +113,7 @@ TEST_F(NestedDispatcherTest, AssociatedWindowBelowLockScreen) {

Shell::GetInstance()->session_state_delegate()->LockScreen();
DispatchKeyReleaseA();
aura::RootWindow* root_window = ash::Shell::GetPrimaryRootWindow();
aura::Window* root_window = ash::Shell::GetPrimaryRootWindow();
aura::client::GetDispatcherClient(root_window)->RunWithDispatcher(
&inner_dispatcher,
associated_window.get(),
Expand All @@ -132,7 +134,7 @@ TEST_F(NestedDispatcherTest, AssociatedWindowAboveLockScreen) {
mock_lock_container.get()));

DispatchKeyReleaseA();
aura::RootWindow* root_window = ash::Shell::GetPrimaryRootWindow();
aura::Window* root_window = ash::Shell::GetPrimaryRootWindow();
aura::client::GetDispatcherClient(root_window)->RunWithDispatcher(
&inner_dispatcher,
associated_window.get(),
Expand All @@ -143,7 +145,7 @@ TEST_F(NestedDispatcherTest, AssociatedWindowAboveLockScreen) {
// Test that the nested dispatcher handles accelerators.
TEST_F(NestedDispatcherTest, AcceleratorsHandled) {
MockDispatcher inner_dispatcher;
aura::RootWindow* root_window = ash::Shell::GetPrimaryRootWindow();
aura::Window* root_window = ash::Shell::GetPrimaryRootWindow();

ui::Accelerator accelerator(ui::VKEY_A, ui::EF_NONE);
accelerator.set_type(ui::ET_KEY_RELEASED);
Expand Down
10 changes: 6 additions & 4 deletions ash/autoclick/autoclick_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ void AutoclickControllerImpl::OnTouchEvent(ui::TouchEvent* event) {
void AutoclickControllerImpl::DoAutoclick() {
gfx::Point screen_location =
aura::Env::GetInstance()->last_mouse_location();
aura::RootWindow* root_window = wm::GetRootWindowAt(screen_location);
aura::Window* root_window = wm::GetRootWindowAt(screen_location);
DCHECK(root_window) << "Root window not found while attempting autoclick.";

gfx::Point click_location(screen_location);
anchor_location_ = click_location;
wm::ConvertPointFromScreen(root_window, &click_location);
root_window->ConvertPointToHost(&click_location);

aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher();
dispatcher->ConvertPointToHost(&click_location);

ui::MouseEvent press_event(ui::ET_MOUSE_PRESSED,
click_location,
Expand All @@ -171,8 +173,8 @@ void AutoclickControllerImpl::DoAutoclick() {
click_location,
mouse_event_flags_ | ui::EF_LEFT_MOUSE_BUTTON);

root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&press_event);
root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&release_event);
dispatcher->AsRootWindowHostDelegate()->OnHostMouseEvent(&press_event);
dispatcher->AsRootWindowHostDelegate()->OnHostMouseEvent(&release_event);
}

// static.
Expand Down
1 change: 1 addition & 0 deletions ash/autoclick/autoclick_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ash/autoclick/autoclick_controller.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/window.h"
#include "ui/events/event.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const int kLockScreenBackgroundId =

// Returns number of child windows in a shell window container.
int ChildCountForContainer(int container_id) {
RootWindow* root = ash::Shell::GetPrimaryRootWindow();
Window* root = ash::Shell::GetPrimaryRootWindow();
Window* container = root->GetChildById(container_id);
return static_cast<int>(container->children().size());
}
Expand Down
4 changes: 2 additions & 2 deletions ash/dip_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ typedef ash::test::AshTestBase DIPTest;
TEST_F(DIPTest, WorkArea) {
UpdateDisplay("1000x900*1.0f");

aura::RootWindow* root = Shell::GetPrimaryRootWindow();
aura::Window* root = Shell::GetPrimaryRootWindow();
const gfx::Display display =
Shell::GetScreen()->GetDisplayNearestWindow(root);

Expand Down Expand Up @@ -74,7 +74,7 @@ TEST_F(DIPTest, WorkAreaForLegacyShelfLayout) {
ash::switches::kAshDisableAlternateShelfLayout);
UpdateDisplay("1000x900*1.0f");

aura::RootWindow* root = Shell::GetPrimaryRootWindow();
aura::Window* root = Shell::GetPrimaryRootWindow();
const gfx::Display display =
Shell::GetScreen()->GetDisplayNearestWindow(root);

Expand Down
30 changes: 16 additions & 14 deletions ash/display/display_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class FocusActivationStore {

void Store(bool display_removed) {
if (!activation_client_) {
aura::RootWindow* root = Shell::GetPrimaryRootWindow();
aura::Window* root = Shell::GetPrimaryRootWindow();
activation_client_ = aura::client::GetActivationClient(root);
capture_client_ = aura::client::GetCaptureClient(root);
focus_client_ = aura::client::GetFocusClient(root);
Expand Down Expand Up @@ -311,12 +311,12 @@ void DisplayController::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}

aura::RootWindow* DisplayController::GetPrimaryRootWindow() {
aura::Window* DisplayController::GetPrimaryRootWindow() {
DCHECK(!root_windows_.empty());
return root_windows_[primary_display_id];
}

aura::RootWindow* DisplayController::GetRootWindowForDisplayId(int64 id) {
aura::Window* DisplayController::GetRootWindowForDisplayId(int64 id) {
return root_windows_[id];
}

Expand Down Expand Up @@ -495,12 +495,12 @@ void DisplayController::EnsurePointerInDisplays() {
int64 closest_distance_squared = -1;
internal::DisplayManager* display_manager = GetDisplayManager();

aura::RootWindow* dst_root_window = NULL;
aura::Window* dst_root_window = NULL;
for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
const gfx::Display& display = display_manager->GetDisplayAt(i);
const internal::DisplayInfo display_info =
display_manager->GetDisplayInfo(display.id());
aura::RootWindow* root_window = GetRootWindowForDisplayId(display.id());
aura::Window* root_window = GetRootWindowForDisplayId(display.id());
if (display_info.bounds_in_native().Contains(
cursor_location_in_native_coords_for_restore_)) {
dst_root_window = root_window;
Expand All @@ -517,24 +517,25 @@ void DisplayController::EnsurePointerInDisplays() {
int64 distance_squared = (center - point_in_screen).LengthSquared();
if (closest_distance_squared < 0 ||
closest_distance_squared > distance_squared) {
aura::RootWindow* root_window = GetRootWindowForDisplayId(display.id());
aura::Window* root_window = GetRootWindowForDisplayId(display.id());
aura::client::ScreenPositionClient* client =
aura::client::GetScreenPositionClient(root_window);
client->ConvertPointFromScreen(root_window, &center);
root_window->ConvertPointToNativeScreen(&center);
root_window->GetDispatcher()->ConvertPointToNativeScreen(&center);
dst_root_window = root_window;
target_location_in_native = center;
closest_distance_squared = distance_squared;
}
}
dst_root_window->ConvertPointFromNativeScreen(&target_location_in_native);
dst_root_window->GetDispatcher()->ConvertPointFromNativeScreen(
&target_location_in_native);
dst_root_window->MoveCursorTo(target_location_in_native);
}

bool DisplayController::UpdateWorkAreaOfDisplayNearestWindow(
const aura::Window* window,
const gfx::Insets& insets) {
const aura::RootWindow* root_window = window->GetRootWindow();
const aura::Window* root_window = window->GetRootWindow();
int64 id = internal::GetRootWindowSettings(root_window)->display_id;
// if id is |kInvaildDisplayID|, it's being deleted.
DCHECK(id != gfx::Display::kInvalidDisplayID);
Expand All @@ -545,7 +546,7 @@ const gfx::Display& DisplayController::GetDisplayNearestWindow(
const aura::Window* window) const {
if (!window)
return GetPrimaryDisplay();
const aura::RootWindow* root_window = window->GetRootWindow();
const aura::Window* root_window = window->GetRootWindow();
if (!root_window)
return GetPrimaryDisplay();
int64 id = internal::GetRootWindowSettings(root_window)->display_id;
Expand Down Expand Up @@ -689,12 +690,12 @@ void DisplayController::PreDisplayConfigurationChange(bool display_removed) {
gfx::Point point_in_screen = Shell::GetScreen()->GetCursorScreenPoint();
gfx::Display display =
Shell::GetScreen()->GetDisplayNearestPoint(point_in_screen);
aura::RootWindow* root_window = GetRootWindowForDisplayId(display.id());
aura::Window* root_window = GetRootWindowForDisplayId(display.id());

aura::client::ScreenPositionClient* client =
aura::client::GetScreenPositionClient(root_window);
client->ConvertPointFromScreen(root_window, &point_in_screen);
root_window->ConvertPointToNativeScreen(&point_in_screen);
root_window->GetDispatcher()->ConvertPointToNativeScreen(&point_in_screen);
cursor_location_in_native_coords_for_restore_ = point_in_screen;
}

Expand Down Expand Up @@ -772,12 +773,13 @@ void DisplayController::UpdateHostWindowNames() {
// crbug.com/120229 - set the window title for the primary dislpay
// to "aura_root_0" so gtalk can find the primary root window to broadcast.
// TODO(jhorwich) Remove this once Chrome supports window-based broadcasting.
aura::RootWindow* primary = Shell::GetPrimaryRootWindow();
aura::Window* primary = Shell::GetPrimaryRootWindow();
Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
for (size_t i = 0; i < root_windows.size(); ++i) {
std::string name =
root_windows[i] == primary ? "aura_root_0" : "aura_root_x";
gfx::AcceleratedWidget xwindow = root_windows[i]->GetAcceleratedWidget();
gfx::AcceleratedWidget xwindow =
root_windows[i]->GetDispatcher()->GetAcceleratedWidget();
XStoreName(gfx::GetXDisplay(), xwindow, name.c_str());
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions ash/display/display_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver,
void RemoveObserver(Observer* observer);

// Returns the root window for primary display.
aura::RootWindow* GetPrimaryRootWindow();
aura::Window* GetPrimaryRootWindow();

// Returns the root window for |display_id|.
aura::RootWindow* GetRootWindowForDisplayId(int64 id);
aura::Window* GetRootWindowForDisplayId(int64 id);

// Toggle mirror mode.
void ToggleMirrorMode();
Expand Down
Loading

0 comments on commit bf9cdb3

Please sign in to comment.