diff options
70 files changed, 1488 insertions, 1120 deletions
@@ -14,4 +14,11 @@ include_rules = [ "+net", "+ui", "+win8", + "-ash/host", ] + +specific_include_rules = { + "root_window_controller\.*": [ + "+ash/host" + ], +} diff --git a/ash/accelerators/DEPS b/ash/accelerators/DEPS new file mode 100644 index 0000000..c34af3f --- /dev/null +++ b/ash/accelerators/DEPS @@ -0,0 +1,5 @@ +specific_include_rules = { + "accelerator_controller\.cc": [ + "+ash/host" + ], +} diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc index 17b260e..1d4455a 100644 --- a/ash/accelerators/accelerator_controller.cc +++ b/ash/accelerators/accelerator_controller.cc @@ -18,6 +18,7 @@ #include "ash/display/display_manager.h" #include "ash/focus_cycler.h" #include "ash/gpu_support.h" +#include "ash/host/ash_window_tree_host.h" #include "ash/ime_control_delegate.h" #include "ash/magnifier/magnification_controller.h" #include "ash/magnifier/partial_magnification_controller.h" @@ -498,7 +499,7 @@ bool HandleToggleFullscreen(ui::KeyboardCode key_code) { } bool HandleToggleRootWindowFullScreen() { - Shell::GetPrimaryRootWindow()->GetHost()->ToggleFullScreen(); + Shell::GetPrimaryRootWindowController()->ash_host()->ToggleFullScreen(); return true; } @@ -725,7 +726,7 @@ bool HandlePrintWindowHierarchy() { for (size_t i = 0; i < controllers.size(); ++i) { std::ostringstream out; out << "RootWindow " << i << ":\n"; - PrintWindowHierarchy(controllers[i]->root_window(), 0, &out); + PrintWindowHierarchy(controllers[i]->GetRootWindow(), 0, &out); // Error so logs can be collected from end-users. LOG(ERROR) << out.str(); } diff --git a/ash/ash.gyp b/ash/ash.gyp index 2d882c6..903e4fd 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -184,8 +184,8 @@ 'frame/frame_border_hit_test_controller.h', 'frame/default_header_painter.cc', 'frame/default_header_painter.h', - 'frame/frame_util.cc', - 'frame/frame_util.h', + 'frame/frame_util.cc', + 'frame/frame_util.h', 'frame/header_painter.h', 'frame/header_painter_util.cc', 'frame/header_painter_util.h', @@ -194,9 +194,16 @@ 'gpu_support_stub.h', 'high_contrast/high_contrast_controller.cc', 'high_contrast/high_contrast_controller.h', - 'host/window_tree_host_factory.cc', - 'host/window_tree_host_factory.h', - 'host/window_tree_host_factory_win.cc', + 'host/ash_remote_window_tree_host_win.cc', + 'host/ash_remote_window_tree_host_win.h', + 'host/ash_window_tree_host.h', + 'host/ash_window_tree_host_ozone.cc', + 'host/ash_window_tree_host_win.cc', + 'host/ash_window_tree_host_x11.cc', + 'host/ash_window_tree_host_x11.h', + 'host/root_window_transformer.h', + 'host/transformer_helper.cc', + 'host/transformer_helper.h', 'ime/candidate_view.cc', 'ime/candidate_view.h', 'ime/candidate_window_view.cc', @@ -696,6 +703,10 @@ ['exclude', 'accelerators/spoken_feedback_toggler.cc'], ['exclude', 'accelerators/spoken_feedback_toggler.h'], ], + }, { # else: use_x11==1 + 'dependencies': [ + '../build/linux/system.gyp:xfixes', + ], }], ['chromeos==1', { 'dependencies': [ @@ -912,6 +923,7 @@ 'frame/caption_buttons/frame_maximize_button_unittest.cc', 'frame/custom_frame_view_ash_unittest.cc', 'frame/default_header_painter_unittest.cc', + 'host/ash_window_tree_host_x11_unittest.cc', 'ime/candidate_window_view_unittest.cc', 'ime/input_method_menu_item_unittest.cc', 'ime/input_method_menu_manager_unittest.cc', diff --git a/ash/cancel_mode.cc b/ash/cancel_mode.cc index 96d7dcd..c065b0f 100644 --- a/ash/cancel_mode.cc +++ b/ash/cancel_mode.cc @@ -15,7 +15,7 @@ void DispatchCancelMode() { Shell::GetAllRootWindowControllers()); for (Shell::RootWindowControllerList::const_iterator i = controllers.begin(); i != controllers.end(); ++i) { - (*i)->host()->dispatcher()->DispatchCancelModeEvent(); + (*i)->GetHost()->dispatcher()->DispatchCancelModeEvent(); } } diff --git a/ash/desktop_background/desktop_background_controller.cc b/ash/desktop_background/desktop_background_controller.cc index fe111c0..bada383 100644 --- a/ash/desktop_background/desktop_background_controller.cc +++ b/ash/desktop_background/desktop_background_controller.cc @@ -258,10 +258,10 @@ bool DesktopBackgroundController::ReparentBackgroundWidgets(int src_container, DesktopBackgroundWidgetController* desktop_controller = root_window_controller->wallpaper_controller(); if (desktop_controller) { - moved |= desktop_controller->Reparent( - root_window_controller->root_window(), - src_container, - dst_container); + moved |= + desktop_controller->Reparent(root_window_controller->GetRootWindow(), + src_container, + dst_container); } // During desktop show animations the controller lives in // AnimatingDesktopController owned by RootWindowController. @@ -275,7 +275,7 @@ bool DesktopBackgroundController::ReparentBackgroundWidgets(int src_container, NULL; if (animating_controller) { moved |= animating_controller->Reparent( - root_window_controller->root_window(), + root_window_controller->GetRootWindow(), src_container, dst_container); } diff --git a/ash/display/DEPS b/ash/display/DEPS new file mode 100644 index 0000000..e2976071 --- /dev/null +++ b/ash/display/DEPS @@ -0,0 +1,4 @@ +include_rules = [ + "+ash/host", +] + diff --git a/ash/display/cursor_window_controller.cc b/ash/display/cursor_window_controller.cc index d79f5c5..ad3e9d1 100644 --- a/ash/display/cursor_window_controller.cc +++ b/ash/display/cursor_window_controller.cc @@ -117,9 +117,10 @@ void CursorWindowController::UpdateContainer() { if (is_cursor_compositing_enabled_) { SetDisplay(display_); } else { - aura::WindowTreeHost* mirror_host = Shell::GetInstance()-> - display_controller()->mirror_window_controller()->host(); - SetContainer(mirror_host ? mirror_host->window() : NULL); + SetContainer(Shell::GetInstance()-> + display_controller()-> + mirror_window_controller()-> + GetWindow()); } } diff --git a/ash/display/display_controller.cc b/ash/display/display_controller.cc index 6a4931d..11c49ce 100644 --- a/ash/display/display_controller.cc +++ b/ash/display/display_controller.cc @@ -15,7 +15,8 @@ #include "ash/display/mirror_window_controller.h" #include "ash/display/root_window_transformers.h" #include "ash/display/virtual_keyboard_window_controller.h" -#include "ash/host/window_tree_host_factory.h" +#include "ash/host/ash_window_tree_host.h" +#include "ash/host/root_window_transformer.h" #include "ash/root_window_controller.h" #include "ash/root_window_settings.h" #include "ash/screen_util.h" @@ -27,11 +28,11 @@ #include "ui/aura/client/capture_client.h" #include "ui/aura/client/focus_client.h" #include "ui/aura/client/screen_position_client.h" -#include "ui/aura/root_window_transformer.h" #include "ui/aura/window.h" #include "ui/aura/window_event_dispatcher.h" #include "ui/aura/window_property.h" #include "ui/aura/window_tracker.h" +#include "ui/aura/window_tree_host.h" #include "ui/compositor/compositor.h" #include "ui/compositor/compositor_vsync_manager.h" #include "ui/gfx/display.h" @@ -76,9 +77,10 @@ DisplayManager* GetDisplayManager() { return Shell::GetInstance()->display_manager(); } -void SetDisplayPropertiesOnHost(aura::WindowTreeHost* host, +void SetDisplayPropertiesOnHost(AshWindowTreeHost* ash_host, const gfx::Display& display) { DisplayInfo info = GetDisplayManager()->GetDisplayInfo(display.id()); + aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); #if defined(OS_CHROMEOS) && defined(USE_X11) // Native window property (Atom in X11) that specifies the display's // rotation, scale factor and if it's internal display. They are @@ -116,9 +118,9 @@ void SetDisplayPropertiesOnHost(aura::WindowTreeHost* host, kCARDINAL, 100 * display.device_scale_factor()); #endif - scoped_ptr<aura::RootWindowTransformer> transformer( + scoped_ptr<RootWindowTransformer> transformer( CreateRootWindowTransformerForDisplay(host->window(), display)); - host->SetRootWindowTransformer(transformer.Pass()); + ash_host->SetRootWindowTransformer(transformer.Pass()); DisplayMode mode; if (GetDisplayManager()->GetSelectedModeForDisplayId(display.id(), &mode) && @@ -129,6 +131,10 @@ void SetDisplayPropertiesOnHost(aura::WindowTreeHost* host, } } +aura::Window* GetWindow(AshWindowTreeHost* ash_host) { + return ash_host->AsWindowTreeHost()->window(); +} + } // namespace // A utility class to store/restore focused/active window @@ -218,7 +224,7 @@ bool DisplayController::DisplayChangeLimiter::IsThrottled() const { // DisplayController DisplayController::DisplayController() - : primary_root_window_for_replace_(NULL), + : primary_tree_host_for_replace_(NULL), focus_activation_store_(new FocusActivationStore()), cursor_window_controller_(new CursorWindowController()), mirror_window_controller_(new MirrorWindowController()) { @@ -257,28 +263,34 @@ void DisplayController::Shutdown() { Shell::GetScreen()->RemoveObserver(this); // Delete all root window controllers, which deletes root window // from the last so that the primary root window gets deleted last. - for (std::map<int64, aura::Window*>::const_reverse_iterator it = - root_windows_.rbegin(); it != root_windows_.rend(); ++it) { - RootWindowController* controller = GetRootWindowController(it->second); + for (WindowTreeHostMap::const_reverse_iterator it = + window_tree_hosts_.rbegin(); + it != window_tree_hosts_.rend(); + ++it) { + RootWindowController* controller = + GetRootWindowController(GetWindow(it->second)); DCHECK(controller); delete controller; } } -void DisplayController::InitPrimaryDisplay() { +void DisplayController::CreatePrimaryHost() { const gfx::Display& primary_candidate = GetDisplayManager()->GetPrimaryDisplayCandidate(); primary_display_id = primary_candidate.id(); AddWindowTreeHostForDisplay(primary_candidate); } -void DisplayController::InitSecondaryDisplays() { +void DisplayController::InitDisplays() { + RootWindowController::CreateForPrimaryDisplay( + window_tree_hosts_[primary_display_id]); + DisplayManager* display_manager = GetDisplayManager(); for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { const gfx::Display& display = display_manager->GetDisplayAt(i); if (primary_display_id != display.id()) { - aura::WindowTreeHost* host = AddWindowTreeHostForDisplay(display); - RootWindowController::CreateForSecondaryDisplay(host); + AshWindowTreeHost* ash_host = AddWindowTreeHostForDisplay(display); + RootWindowController::CreateForSecondaryDisplay(ash_host); } } UpdateHostWindowNames(); @@ -298,18 +310,19 @@ int64 DisplayController::GetPrimaryDisplayId() { } aura::Window* DisplayController::GetPrimaryRootWindow() { - DCHECK(!root_windows_.empty()); - return root_windows_[primary_display_id]; + return GetRootWindowForDisplayId(primary_display_id); } aura::Window* DisplayController::GetRootWindowForDisplayId(int64 id) { - return root_windows_[id]; + DCHECK_EQ(1u, window_tree_hosts_.count(id)); + return GetWindow(window_tree_hosts_[id]); } void DisplayController::CloseChildWindows() { - for (std::map<int64, aura::Window*>::const_iterator it = - root_windows_.begin(); it != root_windows_.end(); ++it) { - aura::Window* root_window = it->second; + for (WindowTreeHostMap::const_iterator it = window_tree_hosts_.begin(); + it != window_tree_hosts_.end(); + ++it) { + aura::Window* root_window = GetWindow(it->second); RootWindowController* controller = GetRootWindowController(root_window); if (controller) { controller->CloseChildWindows(); @@ -324,11 +337,12 @@ void DisplayController::CloseChildWindows() { aura::Window::Windows DisplayController::GetAllRootWindows() { aura::Window::Windows windows; - for (std::map<int64, aura::Window*>::const_iterator it = - root_windows_.begin(); it != root_windows_.end(); ++it) { + for (WindowTreeHostMap::const_iterator it = window_tree_hosts_.begin(); + it != window_tree_hosts_.end(); + ++it) { DCHECK(it->second); - if (GetRootWindowController(it->second)) - windows.push_back(it->second); + if (GetRootWindowController(GetWindow(it->second))) + windows.push_back(GetWindow(it->second)); } return windows; } @@ -345,9 +359,11 @@ void DisplayController::SetOverscanInsets(int64 display_id, std::vector<RootWindowController*> DisplayController::GetAllRootWindowControllers() { std::vector<RootWindowController*> controllers; - for (std::map<int64, aura::Window*>::const_iterator it = - root_windows_.begin(); it != root_windows_.end(); ++it) { - RootWindowController* controller = GetRootWindowController(it->second); + for (WindowTreeHostMap::const_iterator it = window_tree_hosts_.begin(); + it != window_tree_hosts_.end(); + ++it) { + RootWindowController* controller = + GetRootWindowController(GetWindow(it->second)); if (controller) controllers.push_back(controller); } @@ -423,39 +439,41 @@ void DisplayController::SetPrimaryDisplay( } if (primary_display_id == new_primary_display.id() || - root_windows_.size() < 2) { + window_tree_hosts_.size() < 2) { return; } - aura::Window* non_primary_root = root_windows_[new_primary_display.id()]; - LOG_IF(ERROR, !non_primary_root) + AshWindowTreeHost* non_primary_host = + window_tree_hosts_[new_primary_display.id()]; + LOG_IF(ERROR, !non_primary_host) << "Unknown display is requested in SetPrimaryDisplay: id=" << new_primary_display.id(); - if (!non_primary_root) + if (!non_primary_host) return; gfx::Display old_primary_display = Shell::GetScreen()->GetPrimaryDisplay(); // Swap root windows between current and new primary display. - aura::Window* primary_root = root_windows_[primary_display_id]; - DCHECK(primary_root); - DCHECK_NE(primary_root, non_primary_root); + AshWindowTreeHost* primary_host = window_tree_hosts_[primary_display_id]; + DCHECK(primary_host); + DCHECK_NE(primary_host, non_primary_host); - root_windows_[new_primary_display.id()] = primary_root; - GetRootWindowSettings(primary_root)->display_id = new_primary_display.id(); + window_tree_hosts_[new_primary_display.id()] = primary_host; + GetRootWindowSettings(GetWindow(primary_host))->display_id = + new_primary_display.id(); - root_windows_[old_primary_display.id()] = non_primary_root; - GetRootWindowSettings(non_primary_root)->display_id = + window_tree_hosts_[old_primary_display.id()] = non_primary_host; + GetRootWindowSettings(GetWindow(non_primary_host))->display_id = old_primary_display.id(); primary_display_id = new_primary_display.id(); GetDisplayManager()->layout_store()->UpdatePrimaryDisplayId( display_manager->GetCurrentDisplayIdPair(), primary_display_id); - UpdateWorkAreaOfDisplayNearestWindow( - primary_root, old_primary_display.GetWorkAreaInsets()); - UpdateWorkAreaOfDisplayNearestWindow( - non_primary_root, new_primary_display.GetWorkAreaInsets()); + UpdateWorkAreaOfDisplayNearestWindow(GetWindow(primary_host), + old_primary_display.GetWorkAreaInsets()); + UpdateWorkAreaOfDisplayNearestWindow(GetWindow(non_primary_host), + new_primary_display.GetWorkAreaInsets()); // Update the dispay manager with new display info. std::vector<DisplayInfo> display_info_list; @@ -529,67 +547,69 @@ void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) { const DisplayInfo& display_info = GetDisplayManager()->GetDisplayInfo(display.id()); DCHECK(!display_info.bounds_in_native().IsEmpty()); - aura::WindowTreeHost* host = root_windows_[display.id()]->GetHost(); - host->SetBounds(display_info.bounds_in_native()); - SetDisplayPropertiesOnHost(host, display); + AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; + ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); + SetDisplayPropertiesOnHost(ash_host, display); } void DisplayController::OnDisplayAdded(const gfx::Display& display) { - if (primary_root_window_for_replace_) { - DCHECK(root_windows_.empty()); + if (primary_tree_host_for_replace_) { + DCHECK(window_tree_hosts_.empty()); primary_display_id = display.id(); - root_windows_[display.id()] = primary_root_window_for_replace_; - GetRootWindowSettings(primary_root_window_for_replace_)->display_id = - display.id(); - primary_root_window_for_replace_ = NULL; + window_tree_hosts_[display.id()] = primary_tree_host_for_replace_; + GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_)) + ->display_id = display.id(); + primary_tree_host_for_replace_ = NULL; const DisplayInfo& display_info = GetDisplayManager()->GetDisplayInfo(display.id()); - aura::WindowTreeHost* host = root_windows_[display.id()]->GetHost(); - host->SetBounds(display_info.bounds_in_native()); - SetDisplayPropertiesOnHost(host, display); + AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; + ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); + SetDisplayPropertiesOnHost(ash_host, display); } else { if (primary_display_id == gfx::Display::kInvalidDisplayID) primary_display_id = display.id(); - DCHECK(!root_windows_.empty()); - aura::WindowTreeHost* host = AddWindowTreeHostForDisplay(display); - RootWindowController::CreateForSecondaryDisplay(host); + DCHECK(!window_tree_hosts_.empty()); + AshWindowTreeHost* ash_host = AddWindowTreeHostForDisplay(display); + RootWindowController::CreateForSecondaryDisplay(ash_host); } } void DisplayController::OnDisplayRemoved(const gfx::Display& display) { - aura::Window* root_to_delete = root_windows_[display.id()]; - DCHECK(root_to_delete) << display.ToString(); + AshWindowTreeHost* host_to_delete = window_tree_hosts_[display.id()]; + DCHECK(host_to_delete) << display.ToString(); // Display for root window will be deleted when the Primary RootWindow // is deleted by the Shell. - root_windows_.erase(display.id()); + window_tree_hosts_.erase(display.id()); // When the primary root window's display is removed, move the primary // root to the other display. if (primary_display_id == display.id()) { // Temporarily store the primary root window in // |primary_root_window_for_replace_| when replacing the display. - if (root_windows_.size() == 0) { + if (window_tree_hosts_.size() == 0) { primary_display_id = gfx::Display::kInvalidDisplayID; - primary_root_window_for_replace_ = root_to_delete; + primary_tree_host_for_replace_ = host_to_delete; return; } - DCHECK_EQ(1U, root_windows_.size()); + DCHECK_EQ(1U, window_tree_hosts_.size()); primary_display_id = ScreenUtil::GetSecondaryDisplay().id(); - aura::Window* primary_root = root_to_delete; + AshWindowTreeHost* primary_host = host_to_delete; - // Delete the other root instead. - root_to_delete = root_windows_[primary_display_id]; - GetRootWindowSettings(root_to_delete)->display_id = display.id(); + // Delete the other host instead. + host_to_delete = window_tree_hosts_[primary_display_id]; + GetRootWindowSettings(GetWindow(host_to_delete))->display_id = display.id(); // Setup primary root. - root_windows_[primary_display_id] = primary_root; - GetRootWindowSettings(primary_root)->display_id = primary_display_id; + window_tree_hosts_[primary_display_id] = primary_host; + GetRootWindowSettings(GetWindow(primary_host))->display_id = + primary_display_id; OnDisplayBoundsChanged( GetDisplayManager()->GetDisplayForId(primary_display_id)); } - RootWindowController* controller = GetRootWindowController(root_to_delete); + RootWindowController* controller = + GetRootWindowController(GetWindow(host_to_delete)); DCHECK(controller); controller->MoveWindowsTo(GetPrimaryRootWindow()); // Delete most of root window related objects, but don't delete @@ -679,15 +699,15 @@ void DisplayController::PostDisplayConfigurationChange() { EnsurePointerInDisplays(); } -aura::WindowTreeHost* DisplayController::AddWindowTreeHostForDisplay( +AshWindowTreeHost* DisplayController::AddWindowTreeHostForDisplay( const gfx::Display& display) { static int host_count = 0; const DisplayInfo& display_info = GetDisplayManager()->GetDisplayInfo(display.id()); const gfx::Rect& bounds_in_native = display_info.bounds_in_native(); - aura::WindowTreeHost* host = - Shell::GetInstance()->window_tree_host_factory()->CreateWindowTreeHost( - bounds_in_native); + AshWindowTreeHost* ash_host = AshWindowTreeHost::Create(bounds_in_native); + aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); + host->window()->SetName(base::StringPrintf("RootWindow-%d", host_count++)); host->compositor()->SetBackgroundColor(SK_ColorBLACK); // No need to remove our observer observer because the DisplayController @@ -696,17 +716,17 @@ aura::WindowTreeHost* DisplayController::AddWindowTreeHostForDisplay( InitRootWindowSettings(host->window())->display_id = display.id(); host->InitHost(); - root_windows_[display.id()] = host->window(); - SetDisplayPropertiesOnHost(host, display); + window_tree_hosts_[display.id()] = ash_host; + SetDisplayPropertiesOnHost(ash_host, display); #if defined(OS_CHROMEOS) static bool force_constrain_pointer_to_root = CommandLine::ForCurrentProcess()->HasSwitch( switches::kAshConstrainPointerToRoot); if (base::SysInfo::IsRunningOnChromeOS() || force_constrain_pointer_to_root) - host->ConfineCursorToRootWindow(); + ash_host->ConfineCursorToRootWindow(); #endif - return host; + return ash_host; } void DisplayController::OnFadeOutForSwapDisplayFinished() { diff --git a/ash/display/display_controller.h b/ash/display/display_controller.h index 905b594..fb61b84 100644 --- a/ash/display/display_controller.h +++ b/ash/display/display_controller.h @@ -37,6 +37,7 @@ class Insets; } namespace ash { +class AshWindowTreeHost; class CursorWindowController; class DisplayInfo; class DisplayManager; @@ -91,11 +92,11 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver, return virtual_keyboard_window_controller_.get(); } - // Initializes primary display. - void InitPrimaryDisplay(); + // Create a WindowTreeHost for the primary display. + void CreatePrimaryHost(); - // Initialize secondary displays. - void InitSecondaryDisplays(); + // Initializes all displays. + void InitDisplays(); // Add/Remove observers. void AddObserver(Observer* observer); @@ -166,10 +167,9 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver, friend class DisplayManager; friend class MirrorWindowController; - // Creates a WindowTreeHost for |display| and stores it in the |root_windows_| - // map. - aura::WindowTreeHost* AddWindowTreeHostForDisplay( - const gfx::Display& display); + // Creates a WindowTreeHost for |display| and stores it in the + // |window_tree_hosts_| map. + AshWindowTreeHost* AddWindowTreeHostForDisplay(const gfx::Display& display); void OnFadeOutForSwapDisplayFinished(); @@ -195,14 +195,15 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver, // change the display configuration. scoped_ptr<DisplayChangeLimiter> limiter_; - // The mapping from display ID to its root window. - std::map<int64, aura::Window*> root_windows_; + typedef std::map<int64, AshWindowTreeHost*> WindowTreeHostMap; + // The mapping from display ID to its window tree host. + WindowTreeHostMap window_tree_hosts_; ObserverList<Observer> observers_; - // Store the primary root window temporarily while replacing + // Store the primary window tree host temporarily while replacing // display. - aura::Window* primary_root_window_for_replace_; + AshWindowTreeHost* primary_tree_host_for_replace_; scoped_ptr<FocusActivationStore> focus_activation_store_; diff --git a/ash/display/mirror_window_controller.cc b/ash/display/mirror_window_controller.cc index 69de042..37dcf3b 100644 --- a/ash/display/mirror_window_controller.cc +++ b/ash/display/mirror_window_controller.cc @@ -16,14 +16,15 @@ #include "ash/display/display_info.h" #include "ash/display/display_manager.h" #include "ash/display/root_window_transformers.h" -#include "ash/host/window_tree_host_factory.h" +#include "ash/host/ash_window_tree_host.h" +#include "ash/host/root_window_transformer.h" #include "ash/root_window_settings.h" #include "ash/shell.h" #include "base/strings/stringprintf.h" #include "ui/aura/client/capture_client.h" -#include "ui/aura/root_window_transformer.h" #include "ui/aura/window_delegate.h" #include "ui/aura/window_event_dispatcher.h" +#include "ui/aura/window_tree_host.h" #include "ui/base/layout.h" #include "ui/compositor/reflector.h" #include "ui/gfx/canvas.h" @@ -79,54 +80,54 @@ MirrorWindowController::~MirrorWindowController() { void MirrorWindowController::UpdateWindow(const DisplayInfo& display_info) { static int mirror_host_count = 0; - - if (!host_.get()) { + if (!ash_host_.get()) { const gfx::Rect& bounds_in_native = display_info.bounds_in_native(); - host_.reset(Shell::GetInstance()->window_tree_host_factory()-> - CreateWindowTreeHost(bounds_in_native)); - host_->window()->SetName( + ash_host_.reset(AshWindowTreeHost::Create(bounds_in_native)); + aura::WindowTreeHost* host = ash_host_->AsWindowTreeHost(); + host->window()->SetName( base::StringPrintf("MirrorRootWindow-%d", mirror_host_count++)); - host_->compositor()->SetBackgroundColor(SK_ColorBLACK); + host->compositor()->SetBackgroundColor(SK_ColorBLACK); // No need to remove the observer because the DisplayController outlives the // host. - host_->AddObserver(Shell::GetInstance()->display_controller()); - host_->AddObserver(this); + host->AddObserver(Shell::GetInstance()->display_controller()); + host->AddObserver(this); // TODO(oshima): TouchHUD is using idkey. - InitRootWindowSettings(host_->window())->display_id = display_info.id(); - host_->InitHost(); + InitRootWindowSettings(host->window())->display_id = display_info.id(); + host->InitHost(); #if defined(USE_X11) - DisableInput(host_->GetAcceleratedWidget()); + DisableInput(host->GetAcceleratedWidget()); #endif - aura::client::SetCaptureClient(host_->window(), new NoneCaptureClient()); - host_->Show(); + aura::client::SetCaptureClient(host->window(), new NoneCaptureClient()); + host->Show(); // TODO(oshima): Start mirroring. aura::Window* mirror_window = new aura::Window(NULL); mirror_window->Init(aura::WINDOW_LAYER_TEXTURED); - host_->window()->AddChild(mirror_window); - mirror_window->SetBounds(host_->window()->bounds()); + host->window()->AddChild(mirror_window); + mirror_window->SetBounds(host->window()->bounds()); mirror_window->Show(); reflector_ = ui::ContextFactory::GetInstance()->CreateReflector( Shell::GetPrimaryRootWindow()->GetHost()->compositor(), mirror_window->layer()); } else { - GetRootWindowSettings(host_->window())->display_id = display_info.id(); - host_->SetBounds(display_info.bounds_in_native()); + aura::WindowTreeHost* host = ash_host_->AsWindowTreeHost(); + GetRootWindowSettings(host->window())->display_id = display_info.id(); + host->SetBounds(display_info.bounds_in_native()); } DisplayManager* display_manager = Shell::GetInstance()->display_manager(); const DisplayInfo& source_display_info = display_manager->GetDisplayInfo( Shell::GetScreen()->GetPrimaryDisplay().id()); DCHECK(display_manager->IsMirrored()); - scoped_ptr<aura::RootWindowTransformer> transformer( + scoped_ptr<RootWindowTransformer> transformer( CreateRootWindowTransformerForMirroredDisplay(source_display_info, display_info)); - host_->SetRootWindowTransformer(transformer.Pass()); + ash_host_->SetRootWindowTransformer(transformer.Pass()); } void MirrorWindowController::UpdateWindow() { - if (host_.get()) { + if (ash_host_.get()) { DisplayManager* display_manager = Shell::GetInstance()->display_manager(); const DisplayInfo& mirror_display_info = display_manager->GetDisplayInfo( display_manager->mirrored_display_id()); @@ -135,17 +136,18 @@ void MirrorWindowController::UpdateWindow() { } void MirrorWindowController::Close() { - if (host_.get()) { + if (ash_host_.get()) { + aura::WindowTreeHost* host = ash_host_->AsWindowTreeHost(); ui::ContextFactory::GetInstance()->RemoveReflector(reflector_); reflector_ = NULL; NoneCaptureClient* capture_client = static_cast<NoneCaptureClient*>( - aura::client::GetCaptureClient(host_->window())); - aura::client::SetCaptureClient(host_->window(), NULL); + aura::client::GetCaptureClient(host->window())); + aura::client::SetCaptureClient(host->window(), NULL); delete capture_client; - host_->RemoveObserver(Shell::GetInstance()->display_controller()); - host_->RemoveObserver(this); - host_.reset(); + host->RemoveObserver(Shell::GetInstance()->display_controller()); + host->RemoveObserver(this); + ash_host_.reset(); } } @@ -154,13 +156,16 @@ void MirrorWindowController::OnHostResized(const aura::WindowTreeHost* host) { return; mirror_window_host_size_ = host->GetBounds().size(); reflector_->OnMirroringCompositorResized(); - host_->SetRootWindowTransformer(CreateRootWindowTransformer().Pass()); + ash_host_->SetRootWindowTransformer(CreateRootWindowTransformer().Pass()); Shell::GetInstance()->display_controller()->cursor_window_controller()-> UpdateLocation(); } +aura::Window* MirrorWindowController::GetWindow() { + return ash_host_.get() ? ash_host_->AsWindowTreeHost()->window() : NULL; +} -scoped_ptr<aura::RootWindowTransformer> +scoped_ptr<RootWindowTransformer> MirrorWindowController::CreateRootWindowTransformer() const { DisplayManager* display_manager = Shell::GetInstance()->display_manager(); const DisplayInfo& mirror_display_info = display_manager->GetDisplayInfo( @@ -168,7 +173,7 @@ MirrorWindowController::CreateRootWindowTransformer() const { const DisplayInfo& source_display_info = display_manager->GetDisplayInfo( Shell::GetScreen()->GetPrimaryDisplay().id()); DCHECK(display_manager->IsMirrored()); - return scoped_ptr<aura::RootWindowTransformer>( + return scoped_ptr<RootWindowTransformer>( CreateRootWindowTransformerForMirroredDisplay(source_display_info, mirror_display_info)); } diff --git a/ash/display/mirror_window_controller.h b/ash/display/mirror_window_controller.h index 89b2b61..beb703a 100644 --- a/ash/display/mirror_window_controller.h +++ b/ash/display/mirror_window_controller.h @@ -9,15 +9,11 @@ #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" -#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host_observer.h" -#include "ui/gfx/display.h" #include "ui/gfx/native_widget_types.h" -#include "ui/gfx/point.h" #include "ui/gfx/size.h" namespace aura { -class RootWindowTransformer; class Window; } @@ -26,7 +22,9 @@ class Reflector; } namespace ash { +class AshWindowTreeHost; class DisplayInfo; +class RootWindowTransformer; namespace test{ class MirrorWindowTestApi; @@ -54,16 +52,18 @@ class ASH_EXPORT MirrorWindowController : public aura::WindowTreeHostObserver { // aura::WindowTreeHostObserver overrides: virtual void OnHostResized(const aura::WindowTreeHost* host) OVERRIDE; - aura::WindowTreeHost* host() const { return host_.get(); } + // Return the root window used to mirror the content. NULL if the + // display is not mirrored by the compositor path. + aura::Window* GetWindow(); private: friend class test::MirrorWindowTestApi; // Creates a RootWindowTransformer for current display // configuration. - scoped_ptr<aura::RootWindowTransformer> CreateRootWindowTransformer() const; + scoped_ptr<RootWindowTransformer> CreateRootWindowTransformer() const; - scoped_ptr<aura::WindowTreeHost> host_; + scoped_ptr<AshWindowTreeHost> ash_host_; gfx::Size mirror_window_host_size_; scoped_refptr<ui::Reflector> reflector_; diff --git a/ash/display/root_window_transformers.cc b/ash/display/root_window_transformers.cc index a632eb3..cba6688 100644 --- a/ash/display/root_window_transformers.cc +++ b/ash/display/root_window_transformers.cc @@ -8,12 +8,12 @@ #include "ash/display/display_info.h" #include "ash/display/display_manager.h" +#include "ash/host/root_window_transformer.h" #include "ash/magnifier/magnification_controller.h" #include "ash/shell.h" #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "third_party/skia/include/utils/SkMatrix44.h" -#include "ui/aura/root_window_transformer.h" #include "ui/aura/window_event_dispatcher.h" #include "ui/aura/window_property.h" #include "ui/compositor/dip_util.h" @@ -123,7 +123,7 @@ gfx::Transform CreateInsetsAndScaleTransform(const gfx::Insets& insets, } // RootWindowTransformer for ash environment. -class AshRootWindowTransformer : public aura::RootWindowTransformer { +class AshRootWindowTransformer : public RootWindowTransformer { public: AshRootWindowTransformer(aura::Window* root, const gfx::Display& display) @@ -139,7 +139,6 @@ class AshRootWindowTransformer : public aura::RootWindowTransformer { CreateRotationTransform(root, display); transform_ = root_window_bounds_transform_ * CreateMagnifierTransform(root); CHECK(transform_.GetInverse(&invert_transform_)); - } // aura::RootWindowTransformer overrides: @@ -201,7 +200,7 @@ class AshRootWindowTransformer : public aura::RootWindowTransformer { // texture (bitmap) of the source display into the mirror window, so // the root window bounds is the same as the source display's // pixel size (excluding overscan insets). -class MirrorRootWindowTransformer : public aura::RootWindowTransformer { +class MirrorRootWindowTransformer : public RootWindowTransformer { public: MirrorRootWindowTransformer(const DisplayInfo& source_display_info, const DisplayInfo& mirror_display_info) { @@ -267,13 +266,13 @@ class MirrorRootWindowTransformer : public aura::RootWindowTransformer { } // namespace -aura::RootWindowTransformer* CreateRootWindowTransformerForDisplay( +RootWindowTransformer* CreateRootWindowTransformerForDisplay( aura::Window* root, const gfx::Display& display) { return new AshRootWindowTransformer(root, display); } -aura::RootWindowTransformer* CreateRootWindowTransformerForMirroredDisplay( +RootWindowTransformer* CreateRootWindowTransformerForMirroredDisplay( const DisplayInfo& source_display_info, const DisplayInfo& mirror_display_info) { return new MirrorRootWindowTransformer(source_display_info, diff --git a/ash/display/root_window_transformers.h b/ash/display/root_window_transformers.h index a6f2b5c..b41ccdf 100644 --- a/ash/display/root_window_transformers.h +++ b/ash/display/root_window_transformers.h @@ -8,7 +8,6 @@ #include "ash/ash_export.h" namespace aura { -class RootWindowTransformer; class Window; } @@ -19,8 +18,9 @@ class Transform; namespace ash { class DisplayInfo; +class RootWindowTransformer; -ASH_EXPORT aura::RootWindowTransformer* CreateRootWindowTransformerForDisplay( +ASH_EXPORT RootWindowTransformer* CreateRootWindowTransformerForDisplay( aura::Window* root, const gfx::Display& display); @@ -28,8 +28,7 @@ ASH_EXPORT aura::RootWindowTransformer* CreateRootWindowTransformerForDisplay( // |source_display_info| specifies the display being mirrored, // and |mirror_display_info| specifies the display used to // mirror the content. -ASH_EXPORT aura::RootWindowTransformer* -CreateRootWindowTransformerForMirroredDisplay( +ASH_EXPORT RootWindowTransformer* CreateRootWindowTransformerForMirroredDisplay( const DisplayInfo& source_display_info, const DisplayInfo& mirror_display_info); diff --git a/ash/display/root_window_transformers_unittest.cc b/ash/display/root_window_transformers_unittest.cc index b41b75f..62d7681 100644 --- a/ash/display/root_window_transformers_unittest.cc +++ b/ash/display/root_window_transformers_unittest.cc @@ -6,6 +6,7 @@ #include "ash/display/display_info.h" #include "ash/display/display_manager.h" +#include "ash/host/root_window_transformer.h" #include "ash/magnifier/magnification_controller.h" #include "ash/screen_util.h" #include "ash/shelf/shelf.h" @@ -16,7 +17,6 @@ #include "ash/test/mirror_window_test_api.h" #include "base/synchronization/waitable_event.h" #include "ui/aura/env.h" -#include "ui/aura/root_window_transformer.h" #include "ui/aura/test/event_generator.h" #include "ui/aura/window_event_dispatcher.h" #include "ui/aura/window_tracker.h" @@ -397,7 +397,7 @@ TEST_F(RootWindowTransformersTest, LetterBoxPillarBox) { DisplayManager* display_manager = Shell::GetInstance()->display_manager(); display_manager->SetSecondDisplayMode(DisplayManager::MIRRORING); UpdateDisplay("400x200,500x500"); - scoped_ptr<aura::RootWindowTransformer> transformer( + scoped_ptr<RootWindowTransformer> transformer( test_api.CreateCurrentRootWindowTransformer()); // Y margin must be margin is (500 - 500/400 * 200) / 2 = 125. EXPECT_EQ("0,125,0,125", transformer->GetHostInsets().ToString()); diff --git a/ash/display/virtual_keyboard_window_controller.cc b/ash/display/virtual_keyboard_window_controller.cc index 58597b3..1cec588 100644 --- a/ash/display/virtual_keyboard_window_controller.cc +++ b/ash/display/virtual_keyboard_window_controller.cc @@ -8,7 +8,8 @@ #include "ash/display/display_info.h" #include "ash/display/display_manager.h" #include "ash/display/root_window_transformers.h" -#include "ash/host/window_tree_host_factory.h" +#include "ash/host/ash_window_tree_host.h" +#include "ash/host/root_window_transformer.h" #include "ash/root_window_controller.h" #include "ash/root_window_settings.h" #include "ash/shell.h" @@ -16,7 +17,6 @@ #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "ui/aura/env.h" -#include "ui/aura/root_window_transformer.h" #include "ui/aura/window_event_dispatcher.h" #include "ui/keyboard/keyboard_controller.h" #include "ui/keyboard/keyboard_util.h" @@ -43,26 +43,25 @@ void VirtualKeyboardWindowController::UpdateWindow( static int virtual_keyboard_host_count = 0; if (!root_window_controller_.get()) { const gfx::Rect& bounds_in_native = display_info.bounds_in_native(); - aura::WindowTreeHost* host = - Shell::GetInstance()->window_tree_host_factory()->CreateWindowTreeHost( - bounds_in_native); - host->window()->SetName( - base::StringPrintf("VirtualKeyboardRootWindow-%d", - virtual_keyboard_host_count++)); + AshWindowTreeHost* ash_host = AshWindowTreeHost::Create(bounds_in_native); + aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); + + host->window()->SetName(base::StringPrintf("VirtualKeyboardRootWindow-%d", + virtual_keyboard_host_count++)); // No need to remove WindowTreeHostObserver because the DisplayController // outlives the host. host->AddObserver(Shell::GetInstance()->display_controller()); InitRootWindowSettings(host->window())->display_id = display_info.id(); host->InitHost(); - RootWindowController::CreateForVirtualKeyboardDisplay(host); + RootWindowController::CreateForVirtualKeyboardDisplay(ash_host); root_window_controller_.reset(GetRootWindowController(host->window())); - root_window_controller_->host()->Show(); + root_window_controller_->GetHost()->Show(); root_window_controller_->ActivateKeyboard( keyboard::KeyboardController::GetInstance()); FlipDisplay(); } else { - aura::WindowTreeHost* host = root_window_controller_->host(); + aura::WindowTreeHost* host = root_window_controller_->GetHost(); GetRootWindowSettings(host->window())->display_id = display_info.id(); host->SetBounds(display_info.bounds_in_native()); } @@ -70,7 +69,7 @@ void VirtualKeyboardWindowController::UpdateWindow( void VirtualKeyboardWindowController::Close() { if (root_window_controller_.get()) { - root_window_controller_->host()->RemoveObserver( + root_window_controller_->GetHost()->RemoveObserver( Shell::GetInstance()->display_controller()); root_window_controller_->Shutdown(); root_window_controller_.reset(); @@ -87,11 +86,12 @@ void VirtualKeyboardWindowController::FlipDisplay() { display_manager->SetDisplayRotation( display_manager->non_desktop_display().id(), gfx::Display::ROTATE_180); - aura::WindowTreeHost* host = root_window_controller_->host(); - scoped_ptr<aura::RootWindowTransformer> transformer( + aura::WindowTreeHost* host = root_window_controller_->GetHost(); + scoped_ptr<RootWindowTransformer> transformer( CreateRootWindowTransformerForDisplay( host->window(), display_manager->non_desktop_display())); - host->SetRootWindowTransformer(transformer.Pass()); + root_window_controller_->ash_host()->SetRootWindowTransformer( + transformer.Pass()); } void VirtualKeyboardWindowController::OnMaximizeModeStarted() { diff --git a/ash/host/DEPS b/ash/host/DEPS new file mode 100644 index 0000000..5e3e41c --- /dev/null +++ b/ash/host/DEPS @@ -0,0 +1,6 @@ +include_rules = [ + "-ash", + "+ash/host", + "+ash/ash_export.h", + "+ash/ash_switches.h", +] diff --git a/ash/host/ash_remote_window_tree_host_win.cc b/ash/host/ash_remote_window_tree_host_win.cc new file mode 100644 index 0000000..9b8f8cb --- /dev/null +++ b/ash/host/ash_remote_window_tree_host_win.cc @@ -0,0 +1,72 @@ +// Copyright 2014 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/host/ash_remote_window_tree_host_win.h" + +#include "ash/host/root_window_transformer.h" +#include "ui/gfx/geometry/insets.h" +#include "ui/gfx/transform.h" + +namespace ash { +namespace { +AshRemoteWindowTreeHostWin* g_instance = NULL; +} + +// static +void AshRemoteWindowTreeHostWin::Init() { + DCHECK(!g_instance); + g_instance = new AshRemoteWindowTreeHostWin(); + aura::RemoteWindowTreeHostWin::SetInstance(g_instance); + CHECK_EQ(g_instance, aura::RemoteWindowTreeHostWin::Instance()); +} + +// static +AshRemoteWindowTreeHostWin* AshRemoteWindowTreeHostWin::GetInstance() { + if (!g_instance) + Init(); + CHECK_EQ(g_instance, aura::RemoteWindowTreeHostWin::Instance()); + return g_instance; +} + +AshRemoteWindowTreeHostWin::AshRemoteWindowTreeHostWin() + : aura::RemoteWindowTreeHostWin(gfx::Rect()), transformer_helper_(this) { + g_instance = this; +} + +AshRemoteWindowTreeHostWin::~AshRemoteWindowTreeHostWin() { g_instance = NULL; } + +void AshRemoteWindowTreeHostWin::ToggleFullScreen() {} + +bool AshRemoteWindowTreeHostWin::ConfineCursorToRootWindow() { return false; } + +void AshRemoteWindowTreeHostWin::UnConfineCursor() {} + +void AshRemoteWindowTreeHostWin::SetRootWindowTransformer( + scoped_ptr<RootWindowTransformer> transformer) { + transformer_helper_.SetRootWindowTransformer(transformer.Pass()); +} + +aura::WindowTreeHost* AshRemoteWindowTreeHostWin::AsWindowTreeHost() { + return this; +} + +gfx::Transform AshRemoteWindowTreeHostWin::GetRootTransform() const { + return transformer_helper_.GetTransform(); +} + +void AshRemoteWindowTreeHostWin::SetRootTransform( + const gfx::Transform& transform) { + transformer_helper_.SetTransform(transform); +} + +gfx::Transform AshRemoteWindowTreeHostWin::GetInverseRootTransform() const { + return transformer_helper_.GetInverseTransform(); +} + +void AshRemoteWindowTreeHostWin::UpdateRootWindowSize( + const gfx::Size& host_size) { + transformer_helper_.UpdateWindowSize(host_size); +} + +} // namespace ash diff --git a/ash/host/ash_remote_window_tree_host_win.h b/ash/host/ash_remote_window_tree_host_win.h new file mode 100644 index 0000000..493a7b9 --- /dev/null +++ b/ash/host/ash_remote_window_tree_host_win.h @@ -0,0 +1,53 @@ +// Copyright 2014 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_HOST_REMOTE_WINDOW_TREE_HOST_WIN_H_ +#define ASH_HOST_REMOTE_WINDOW_TREE_HOST_WIN_H_ + +#include "ash/ash_export.h" +#include "ash/host/ash_window_tree_host.h" +#include "ash/host/transformer_helper.h" +#include "ui/aura/remote_window_tree_host_win.h" + +namespace ash { + +class ASH_EXPORT AshRemoteWindowTreeHostWin + : public AshWindowTreeHost, + public aura::RemoteWindowTreeHostWin { + public: + // Creates an instance of AshRemoteWindowTreeHostWin + // and sets it to RemoteWindowTreeHostWin::SetInstance. + static void Init(); + + // Returns the instance created in Init() method above. + // This also performs an extra check if the instance is same + // one that aura::RemoteWindowTreeHostWin::Instance() returns. + static AshRemoteWindowTreeHostWin* GetInstance(); + + private: + AshRemoteWindowTreeHostWin(); + virtual ~AshRemoteWindowTreeHostWin(); + + // AshWindowTreeHost: + virtual void ToggleFullScreen() OVERRIDE; + virtual bool ConfineCursorToRootWindow() OVERRIDE; + virtual void UnConfineCursor() OVERRIDE; + virtual void SetRootWindowTransformer( + scoped_ptr<RootWindowTransformer> transformer) OVERRIDE; + virtual aura::WindowTreeHost* AsWindowTreeHost() OVERRIDE; + + // WindowTreeHostWin: + virtual gfx::Transform GetRootTransform() const OVERRIDE; + virtual void SetRootTransform(const gfx::Transform& transform) OVERRIDE; + virtual gfx::Transform GetInverseRootTransform() const OVERRIDE; + virtual void UpdateRootWindowSize(const gfx::Size& host_size) OVERRIDE; + + TransformerHelper transformer_helper_; + + DISALLOW_COPY_AND_ASSIGN(AshRemoteWindowTreeHostWin); +}; + +} // namespace ash + +#endif // ASH_HOST_REMOTE_WINDOW_TREE_HOST_WIN_H_ diff --git a/ash/host/ash_window_tree_host.h b/ash/host/ash_window_tree_host.h new file mode 100644 index 0000000..9962b89 --- /dev/null +++ b/ash/host/ash_window_tree_host.h @@ -0,0 +1,49 @@ +// Copyright 2014 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_HOST_ASH_WINDOW_TREE_HOST_H_ +#define ASH_HOST_ASH_WINDOW_TREE_HOST_H_ + +#include "ash/ash_export.h" +#include "base/memory/scoped_ptr.h" + +namespace aura { +class Window; +class WindowTreeHost; +} + +namespace gfx { +class Rect; +} + +namespace ash { +class RootWindowTransformer; + +class ASH_EXPORT AshWindowTreeHost { + public: + // Creates a new AshWindowTreeHost. The caller owns the returned value. + static AshWindowTreeHost* Create(const gfx::Rect& initial_bounds); + + virtual ~AshWindowTreeHost() {} + + // Toggles the host's full screen state. + virtual void ToggleFullScreen() = 0; + + // Clips the cursor to the bounds of the root window until UnConfineCursor(). + // We would like to be able to confine the cursor to that window. However, + // currently, we do not have such functionality in X. So we just confine + // to the root window. This is ok because this option is currently only + // being used in fullscreen mode, so root_window bounds = window bounds. + virtual bool ConfineCursorToRootWindow() = 0; + virtual void UnConfineCursor() = 0; + + virtual void SetRootWindowTransformer( + scoped_ptr<RootWindowTransformer> transformer) = 0; + + virtual aura::WindowTreeHost* AsWindowTreeHost() = 0; +}; + +} // namespace ash + +#endif // ASH_HOST_ASH_WINDOW_TREE_HOST_H_ diff --git a/ash/host/ash_window_tree_host_ozone.cc b/ash/host/ash_window_tree_host_ozone.cc new file mode 100644 index 0000000..cfe8b25 --- /dev/null +++ b/ash/host/ash_window_tree_host_ozone.cc @@ -0,0 +1,40 @@ +// Copyright 2014 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/host/ash_window_tree_host.h" + +#include "ash/host/root_window_transformer.h" +#include "base/command_line.h" +#include "ui/aura/window_tree_host_ozone.h" +#include "ui/gfx/geometry/insets.h" + +namespace ash { +namespace { + +class AshWindowTreeHostOzone : public AshWindowTreeHost, + public aura::WindowTreeHostOzone { + public: + explicit AshWindowTreeHostOzone(const gfx::Rect& initial_bounds) + : aura::WindowTreeHostOzone(initial_bounds) {} + virtual ~AshWindowTreeHostOzone() {} + + private: + // AshWindowTreeHost: + virtual void ToggleFullScreen() OVERRIDE { NOTIMPLEMENTED(); } + virtual bool ConfineCursorToRootWindow() OVERRIDE { return false; } + virtual void UnConfineCursor() OVERRIDE { NOTIMPLEMENTED(); } + virtual void SetRootWindowTransformer( + scoped_ptr<RootWindowTransformer> transformer) OVERRIDE {} + virtual aura::WindowTreeHost* AsWindowTreeHost() OVERRIDE { return this; } + + DISALLOW_COPY_AND_ASSIGN(AshWindowTreeHostOzone); +}; + +} // namespace + +AshWindowTreeHost* AshWindowTreeHost::Create(const gfx::Rect& initial_bounds) { + return new AshWindowTreeHostOzone(initial_bounds); +} + +} // namespace ash diff --git a/ash/host/ash_window_tree_host_win.cc b/ash/host/ash_window_tree_host_win.cc new file mode 100644 index 0000000..5ea0f4a --- /dev/null +++ b/ash/host/ash_window_tree_host_win.cc @@ -0,0 +1,119 @@ +// Copyright 2014 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/host/ash_window_tree_host.h" + +#include "ash/ash_export.h" +#include "ash/ash_switches.h" +#include "ash/host/ash_remote_window_tree_host_win.h" +#include "ash/host/root_window_transformer.h" +#include "ash/host/transformer_helper.h" +#include "base/command_line.h" +#include "base/win/windows_version.h" +#include "ui/aura/window_tree_host_win.h" +#include "ui/gfx/geometry/insets.h" +#include "ui/gfx/transform.h" + +namespace ash { +namespace { + +class ASH_EXPORT AshWindowTreeHostWin : public AshWindowTreeHost, + public aura::WindowTreeHostWin { + public: + explicit AshWindowTreeHostWin(const gfx::Rect& initial_bounds) + : aura::WindowTreeHostWin(initial_bounds), + fullscreen_(false), + saved_window_style_(0), + saved_window_ex_style_(0), + transformer_helper_(this) {} + virtual ~AshWindowTreeHostWin() {} + + private: + // AshWindowTreeHost: + virtual void ToggleFullScreen() OVERRIDE { + gfx::Rect target_rect; + if (!fullscreen_) { + fullscreen_ = true; + saved_window_style_ = GetWindowLong(hwnd(), GWL_STYLE); + saved_window_ex_style_ = GetWindowLong(hwnd(), GWL_EXSTYLE); + GetWindowRect(hwnd(), &saved_window_rect_); + SetWindowLong(hwnd(), + GWL_STYLE, + saved_window_style_ & ~(WS_CAPTION | WS_THICKFRAME)); + SetWindowLong( + hwnd(), + GWL_EXSTYLE, + saved_window_ex_style_ & ~(WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | + WS_EX_CLIENTEDGE | WS_EX_STATICEDGE)); + + MONITORINFO mi; + mi.cbSize = sizeof(mi); + GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTONEAREST), &mi); + target_rect = gfx::Rect(mi.rcMonitor); + } else { + fullscreen_ = false; + SetWindowLong(hwnd(), GWL_STYLE, saved_window_style_); + SetWindowLong(hwnd(), GWL_EXSTYLE, saved_window_ex_style_); + target_rect = gfx::Rect(saved_window_rect_); + } + SetWindowPos(hwnd(), + NULL, + target_rect.x(), + target_rect.y(), + target_rect.width(), + target_rect.height(), + SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); + } + virtual bool ConfineCursorToRootWindow() OVERRIDE { return false; } + virtual void UnConfineCursor() OVERRIDE { NOTIMPLEMENTED(); } + virtual void SetRootWindowTransformer( + scoped_ptr<RootWindowTransformer> transformer) { + transformer_helper_.SetRootWindowTransformer(transformer.Pass()); + } + virtual aura::WindowTreeHost* AsWindowTreeHost() OVERRIDE { return this; } + + // WindowTreeHostWin: + virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE { + if (fullscreen_) { + saved_window_rect_.right = saved_window_rect_.left + bounds.width(); + saved_window_rect_.bottom = saved_window_rect_.top + bounds.height(); + return; + } + WindowTreeHostWin::SetBounds(bounds); + } + virtual void SetRootTransform(const gfx::Transform& transform) OVERRIDE { + transformer_helper_.SetTransform(transform); + } + gfx::Transform GetRootTransform() const { + return transformer_helper_.GetTransform(); + } + virtual gfx::Transform GetInverseRootTransform() const OVERRIDE { + return transformer_helper_.GetInverseTransform(); + } + virtual void UpdateRootWindowSize(const gfx::Size& host_size) OVERRIDE { + transformer_helper_.UpdateWindowSize(host_size); + } + + bool fullscreen_; + RECT saved_window_rect_; + DWORD saved_window_style_; + DWORD saved_window_ex_style_; + + TransformerHelper transformer_helper_; + + DISALLOW_COPY_AND_ASSIGN(AshWindowTreeHostWin); +}; + +} // namespace + +AshWindowTreeHost* AshWindowTreeHost::Create(const gfx::Rect& initial_bounds) { + if (base::win::GetVersion() >= base::win::VERSION_WIN8 && + !CommandLine::ForCurrentProcess()->HasSwitch( + ash::switches::kForceAshToDesktop)) + return AshRemoteWindowTreeHostWin::GetInstance(); + + return new AshWindowTreeHostWin(initial_bounds); +} + +} // namespace ash diff --git a/ash/host/ash_window_tree_host_x11.cc b/ash/host/ash_window_tree_host_x11.cc new file mode 100644 index 0000000..e49e961 --- /dev/null +++ b/ash/host/ash_window_tree_host_x11.cc @@ -0,0 +1,418 @@ +// Copyright 2014 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/host/ash_window_tree_host_x11.h" + +#include <X11/extensions/Xfixes.h> +#include <X11/extensions/XInput2.h> +#include <X11/Xatom.h> +#include <X11/Xlib.h> + +#include <string> +#include <vector> + +#include "ash/host/root_window_transformer.h" +#include "base/basictypes.h" +#include "base/command_line.h" +#include "base/strings/string_number_conversions.h" +#include "base/strings/string_util.h" +#include "base/sys_info.h" +#include "ui/aura/client/screen_position_client.h" +#include "ui/aura/env.h" +#include "ui/aura/window.h" +#include "ui/base/x/x11_util.h" +#include "ui/events/event.h" +#include "ui/events/event_switches.h" +#include "ui/events/event_utils.h" +#include "ui/events/platform/platform_event_observer.h" +#include "ui/events/platform/x11/x11_event_source.h" +#include "ui/events/x/device_data_manager.h" +#include "ui/events/x/device_list_cache_x.h" +#include "ui/events/x/touch_factory_x11.h" + +#include "ui/gfx/rect.h" +#include "ui/gfx/screen.h" + +namespace ash { + +// Accomplishes 2 tasks concerning touch event calibration: +// 1. Being a message-pump observer, +// routes all the touch events to the X root window, +// where they can be calibrated later. +// 2. Has the Calibrate method that does the actual bezel calibration, +// when invoked from X root window's event dispatcher. +class AshWindowTreeHostX11::TouchEventCalibrate + : public ui::PlatformEventObserver { + public: + TouchEventCalibrate() : left_(0), right_(0), top_(0), bottom_(0) { + if (ui::PlatformEventSource::GetInstance()) + ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); +#if defined(USE_XI2_MT) + std::vector<std::string> parts; + if (Tokenize(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( + switches::kTouchCalibration), + ",", + &parts) >= 4) { + if (!base::StringToInt(parts[0], &left_)) + DLOG(ERROR) << "Incorrect left border calibration value passed."; + if (!base::StringToInt(parts[1], &right_)) + DLOG(ERROR) << "Incorrect right border calibration value passed."; + if (!base::StringToInt(parts[2], &top_)) + DLOG(ERROR) << "Incorrect top border calibration value passed."; + if (!base::StringToInt(parts[3], &bottom_)) + DLOG(ERROR) << "Incorrect bottom border calibration value passed."; + } +#endif // defined(USE_XI2_MT) + } + + virtual ~TouchEventCalibrate() { + if (ui::PlatformEventSource::GetInstance()) + ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this); + } + + // Modify the location of the |event|, + // expanding it from |bounds| to (|bounds| + bezels). + // Required when touchscreen is bigger than screen (i.e. has bezels), + // because we receive events in touchscreen coordinates, + // which need to be expanded when converting to screen coordinates, + // so that location on bezels will be outside of screen area. + void Calibrate(ui::TouchEvent* event, const gfx::Rect& bounds) { +#if defined(USE_XI2_MT) + int x = event->x(); + int y = event->y(); + + if (!left_ && !right_ && !top_ && !bottom_) + return; + + const int resolution_x = bounds.width(); + const int resolution_y = bounds.height(); + // The "grace area" (10% in this case) is to make it easier for the user to + // navigate to the corner. + const double kGraceAreaFraction = 0.1; + if (left_ || right_) { + // Offset the x position to the real + x -= left_; + // Check if we are in the grace area of the left side. + // Note: We might not want to do this when the gesture is locked? + if (x < 0 && x > -left_ * kGraceAreaFraction) + x = 0; + // Check if we are in the grace area of the right side. + // Note: We might not want to do this when the gesture is locked? + if (x > resolution_x - left_ && + x < resolution_x - left_ + right_ * kGraceAreaFraction) + x = resolution_x - left_; + // Scale the screen area back to the full resolution of the screen. + x = (x * resolution_x) / (resolution_x - (right_ + left_)); + } + if (top_ || bottom_) { + // When there is a top bezel we add our border, + y -= top_; + + // Check if we are in the grace area of the top side. + // Note: We might not want to do this when the gesture is locked? + if (y < 0 && y > -top_ * kGraceAreaFraction) + y = 0; + + // Check if we are in the grace area of the bottom side. + // Note: We might not want to do this when the gesture is locked? + if (y > resolution_y - top_ && + y < resolution_y - top_ + bottom_ * kGraceAreaFraction) + y = resolution_y - top_; + // Scale the screen area back to the full resolution of the screen. + y = (y * resolution_y) / (resolution_y - (bottom_ + top_)); + } + + // Set the modified coordinate back to the event. + if (event->root_location() == event->location()) { + // Usually those will be equal, + // if not, I am not sure what the correct value should be. + event->set_root_location(gfx::Point(x, y)); + } + event->set_location(gfx::Point(x, y)); +#endif // defined(USE_XI2_MT) + } + + private: + // ui::PlatformEventObserver: + virtual void WillProcessEvent(const ui::PlatformEvent& event) OVERRIDE { +#if defined(USE_XI2_MT) + if (event->type == GenericEvent && + (event->xgeneric.evtype == XI_TouchBegin || + event->xgeneric.evtype == XI_TouchUpdate || + event->xgeneric.evtype == XI_TouchEnd)) { + XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event->xcookie.data); + xievent->event = xievent->root; + xievent->event_x = xievent->root_x; + xievent->event_y = xievent->root_y; + } +#endif // defined(USE_XI2_MT) + } + + virtual void DidProcessEvent(const ui::PlatformEvent& event) OVERRIDE {} + + // The difference in screen's native resolution pixels between + // the border of the touchscreen and the border of the screen, + // aka bezel sizes. + int left_; + int right_; + int top_; + int bottom_; + + DISALLOW_COPY_AND_ASSIGN(TouchEventCalibrate); +}; + +//////////////////////////////////////////////////////////////////////////////// +// AshWindowTreeHostX11 + +AshWindowTreeHostX11::AshWindowTreeHostX11(const gfx::Rect& initial_bounds) + : WindowTreeHostX11(initial_bounds), + is_internal_display_(false), + touch_calibrate_(new TouchEventCalibrate), + transformer_helper_(this) { + aura::Env::GetInstance()->AddObserver(this); +} + +AshWindowTreeHostX11::~AshWindowTreeHostX11() { + aura::Env::GetInstance()->RemoveObserver(this); + UnConfineCursor(); +} + +void AshWindowTreeHostX11::ToggleFullScreen() { NOTIMPLEMENTED(); } + +bool AshWindowTreeHostX11::ConfineCursorToRootWindow() { +#if XFIXES_MAJOR >= 5 + DCHECK(!pointer_barriers_.get()); + if (pointer_barriers_) + return false; + pointer_barriers_.reset(new XID[4]); + gfx::Rect barrier(bounds()); + barrier.Inset(transformer_helper_.GetHostInsets()); + // Horizontal, top barriers. + pointer_barriers_[0] = XFixesCreatePointerBarrier(xdisplay(), + x_root_window(), + barrier.x(), + barrier.y(), + barrier.right(), + barrier.y(), + BarrierPositiveY, + 0, + XIAllDevices); + // Horizontal, bottom barriers. + pointer_barriers_[1] = XFixesCreatePointerBarrier(xdisplay(), + x_root_window(), + barrier.x(), + barrier.bottom(), + barrier.right(), + barrier.bottom(), + BarrierNegativeY, + 0, + XIAllDevices); + // Vertical, left barriers. + pointer_barriers_[2] = XFixesCreatePointerBarrier(xdisplay(), + x_root_window(), + barrier.x(), + barrier.y(), + barrier.x(), + barrier.bottom(), + BarrierPositiveX, + 0, + XIAllDevices); + // Vertical, right barriers. + pointer_barriers_[3] = XFixesCreatePointerBarrier(xdisplay(), + x_root_window(), + barrier.right(), + barrier.y(), + barrier.right(), + barrier.bottom(), + BarrierNegativeX, + 0, + XIAllDevices); +#endif + return true; +} + +void AshWindowTreeHostX11::UnConfineCursor() { +#if XFIXES_MAJOR >= 5 + if (pointer_barriers_) { + XFixesDestroyPointerBarrier(xdisplay(), pointer_barriers_[0]); + XFixesDestroyPointerBarrier(xdisplay(), pointer_barriers_[1]); + XFixesDestroyPointerBarrier(xdisplay(), pointer_barriers_[2]); + XFixesDestroyPointerBarrier(xdisplay(), pointer_barriers_[3]); + pointer_barriers_.reset(); + } +#endif +} + +void AshWindowTreeHostX11::SetRootWindowTransformer( + scoped_ptr<RootWindowTransformer> transformer) { + transformer_helper_.SetRootWindowTransformer(transformer.Pass()); + UpdateIsInternalDisplay(); + if (pointer_barriers_) { + UnConfineCursor(); + ConfineCursorToRootWindow(); + } +} + +aura::WindowTreeHost* AshWindowTreeHostX11::AsWindowTreeHost() { return this; } + +void AshWindowTreeHostX11::SetBounds(const gfx::Rect& bounds) { + WindowTreeHostX11::SetBounds(bounds); + UpdateIsInternalDisplay(); + if (pointer_barriers_) { + UnConfineCursor(); + ConfineCursorToRootWindow(); + } +} + +gfx::Transform AshWindowTreeHostX11::GetRootTransform() const { + return transformer_helper_.GetTransform(); +} + +void AshWindowTreeHostX11::SetRootTransform(const gfx::Transform& transform) { + transformer_helper_.SetTransform(transform); +} + +gfx::Transform AshWindowTreeHostX11::GetInverseRootTransform() const { + return transformer_helper_.GetInverseTransform(); +} + +void AshWindowTreeHostX11::UpdateRootWindowSize(const gfx::Size& host_size) { + transformer_helper_.UpdateWindowSize(host_size); +} + +void AshWindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) { + SetCrOSTapPaused(!show); +} + +void AshWindowTreeHostX11::OnWindowInitialized(aura::Window* window) {} + +void AshWindowTreeHostX11::OnHostInitialized(aura::WindowTreeHost* host) { + // UpdateIsInternalDisplay relies on RootWindowSettings' display_id being set + // available by the time WED::Init is called. (set in + // DisplayManager::CreateRootWindowForDisplay) + // Ready when NotifyHostInitialized is called from WED::Init. + if (host != AsWindowTreeHost()) + return; + UpdateIsInternalDisplay(); + + // We have to enable Tap-to-click by default because the cursor is set to + // visible in Shell::InitRootWindowController. + SetCrOSTapPaused(false); +} + +void AshWindowTreeHostX11::OnConfigureNotify() { + UpdateIsInternalDisplay(); + + // Always update barrier and mouse location because |bounds_| might + // have already been updated in |SetBounds|. + if (pointer_barriers_) { + UnConfineCursor(); + ConfineCursorToRootWindow(); + } +} + +void AshWindowTreeHostX11::TranslateAndDispatchLocatedEvent( + ui::LocatedEvent* event) { + switch (event->type()) { + case ui::ET_TOUCH_MOVED: + case ui::ET_TOUCH_PRESSED: + case ui::ET_TOUCH_CANCELLED: + case ui::ET_TOUCH_RELEASED: { + ui::TouchEvent* touchev = static_cast<ui::TouchEvent*>(event); + if (base::SysInfo::IsRunningOnChromeOS()) { + // X maps the touch-surface to the size of the X root-window. + // In multi-monitor setup, Coordinate Transformation Matrix + // repositions the touch-surface onto part of X root-window + // containing aura root-window corresponding to the touchscreen. + // However, if aura root-window has non-zero origin, + // we need to relocate the event into aura root-window coordinates. + touchev->Relocate(bounds().origin()); +#if defined(USE_XI2_MT) + if (is_internal_display_) + touch_calibrate_->Calibrate(touchev, bounds()); +#endif // defined(USE_XI2_MT) + } + break; + } + default: { + aura::Window* root_window = window(); + aura::client::ScreenPositionClient* screen_position_client = + aura::client::GetScreenPositionClient(root_window); + gfx::Rect local(bounds().size()); + + if (screen_position_client && !local.Contains(event->location())) { + gfx::Point location(event->location()); + // In order to get the correct point in screen coordinates + // during passive grab, we first need to find on which host window + // the mouse is on, and find out the screen coordinates on that + // host window, then convert it back to this host window's coordinate. + screen_position_client->ConvertHostPointToScreen(root_window, + &location); + screen_position_client->ConvertPointFromScreen(root_window, &location); + ConvertPointToHost(&location); + event->set_location(location); + event->set_root_location(location); + } + break; + } + } + SendEventToProcessor(event); +} + +void AshWindowTreeHostX11::UpdateIsInternalDisplay() { + aura::Window* root_window = window(); + gfx::Screen* screen = gfx::Screen::GetScreenFor(root_window); + gfx::Display display = screen->GetDisplayNearestWindow(root_window); + DCHECK(display.is_valid()); + is_internal_display_ = display.IsInternal(); +} + +void AshWindowTreeHostX11::SetCrOSTapPaused(bool state) { + if (!ui::IsXInput2Available()) + return; + // Temporarily pause tap-to-click when the cursor is hidden. + Atom prop = atom_cache()->GetAtom("Tap Paused"); + unsigned char value = state; + XIDeviceList dev_list = + ui::DeviceListCacheX::GetInstance()->GetXI2DeviceList(xdisplay()); + + // Only slave pointer devices could possibly have tap-paused property. + for (int i = 0; i < dev_list.count; i++) { + if (dev_list[i].use == XISlavePointer) { + Atom old_type; + int old_format; + unsigned long old_nvalues, bytes; + unsigned char* data; + int result = XIGetProperty(xdisplay(), + dev_list[i].deviceid, + prop, + 0, + 0, + False, + AnyPropertyType, + &old_type, + &old_format, + &old_nvalues, + &bytes, + &data); + if (result != Success) + continue; + XFree(data); + XIChangeProperty(xdisplay(), + dev_list[i].deviceid, + prop, + XA_INTEGER, + 8, + PropModeReplace, + &value, + 1); + } + } +} + +AshWindowTreeHost* AshWindowTreeHost::Create(const gfx::Rect& initial_bounds) { + return new AshWindowTreeHostX11(initial_bounds); +} + +} // namespace ash diff --git a/ash/host/ash_window_tree_host_x11.h b/ash/host/ash_window_tree_host_x11.h new file mode 100644 index 0000000..f690ea8 --- /dev/null +++ b/ash/host/ash_window_tree_host_x11.h @@ -0,0 +1,74 @@ +// Copyright 2014 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_HOST_ASH_WINDOW_TREE_HOST_X11_H_ +#define ASH_HOST_ASH_WINDOW_TREE_HOST_X11_H_ + +#include "ash/ash_export.h" +#include "ash/host/ash_window_tree_host.h" +#include "ash/host/transformer_helper.h" +#include "base/memory/scoped_ptr.h" +#include "ui/aura/env_observer.h" +#include "ui/aura/window_tree_host_x11.h" + +namespace ash { +class RootWindowTransformer; + +class ASH_EXPORT AshWindowTreeHostX11 : public AshWindowTreeHost, + public aura::WindowTreeHostX11, + public aura::EnvObserver { + public: + explicit AshWindowTreeHostX11(const gfx::Rect& initial_bounds); + virtual ~AshWindowTreeHostX11(); + + private: + // AshWindowTreeHost: + virtual void ToggleFullScreen() OVERRIDE; + virtual bool ConfineCursorToRootWindow() OVERRIDE; + virtual void UnConfineCursor() OVERRIDE; + virtual void SetRootWindowTransformer( + scoped_ptr<RootWindowTransformer> transformer) OVERRIDE; + virtual aura::WindowTreeHost* AsWindowTreeHost() OVERRIDE; + + // aura::WindowTreehost: + virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; + virtual gfx::Transform GetRootTransform() const OVERRIDE; + virtual void SetRootTransform(const gfx::Transform& transform) OVERRIDE; + virtual gfx::Transform GetInverseRootTransform() const OVERRIDE; + virtual void UpdateRootWindowSize(const gfx::Size& host_size) OVERRIDE; + virtual void OnCursorVisibilityChangedNative(bool show) OVERRIDE; + + // aura::WindowTreeHostX11: + virtual void OnConfigureNotify() OVERRIDE; + virtual void TranslateAndDispatchLocatedEvent(ui::LocatedEvent* event) + OVERRIDE; + + // EnvObserver overrides. + virtual void OnWindowInitialized(aura::Window* window) OVERRIDE; + virtual void OnHostInitialized(aura::WindowTreeHost* host) OVERRIDE; + + class TouchEventCalibrate; + + // Update is_internal_display_ based on the current state. + void UpdateIsInternalDisplay(); + + // Set the CrOS touchpad "tap paused" property. It is used to temporarily + // turn off the Tap-to-click feature when the mouse pointer is invisible. + void SetCrOSTapPaused(bool state); + + // True if the root host resides on the internal display + bool is_internal_display_; + + scoped_ptr<XID[]> pointer_barriers_; + + scoped_ptr<TouchEventCalibrate> touch_calibrate_; + + TransformerHelper transformer_helper_; + + DISALLOW_COPY_AND_ASSIGN(AshWindowTreeHostX11); +}; + +} // namespace ash + +#endif // ASH_HOST_ASH_WINDOW_TREE_HOST_X11_H_ diff --git a/ui/aura/window_tree_host_x11_unittest.cc b/ash/host/ash_window_tree_host_x11_unittest.cc index 8df6d24..efd25c0 100644 --- a/ui/aura/window_tree_host_x11_unittest.cc +++ b/ash/host/ash_window_tree_host_x11_unittest.cc @@ -1,14 +1,17 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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/host/ash_window_tree_host_x11.h" + +#undef None +#undef Bool #include "base/sys_info.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/aura/test/aura_test_base.h" #include "ui/aura/window.h" #include "ui/aura/window_event_dispatcher.h" -#include "ui/aura/window_tree_host_x11.h" #include "ui/events/event_processor.h" #include "ui/events/event_target.h" #include "ui/events/event_target_iterator.h" @@ -18,11 +21,14 @@ namespace { class RootWindowEventHandler : public ui::EventHandler { public: - RootWindowEventHandler() : last_touch_type_(ui::ET_UNKNOWN), - last_touch_id_(-1), - last_touch_location_(0, 0) { + explicit RootWindowEventHandler(aura::WindowTreeHost* host) + : target_(host->window()), + last_touch_type_(ui::ET_UNKNOWN), + last_touch_id_(-1), + last_touch_location_(0, 0) { + target_->AddPreTargetHandler(this); } - virtual ~RootWindowEventHandler () {} + virtual ~RootWindowEventHandler() { target_->RemovePreTargetHandler(this); } // ui::EventHandler: virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { @@ -31,19 +37,14 @@ class RootWindowEventHandler : public ui::EventHandler { last_touch_location_ = event->location(); } - ui::EventType last_touch_type() { - return last_touch_type_; - } + ui::EventType last_touch_type() { return last_touch_type_; } - int last_touch_id() { - return last_touch_id_; - } + int last_touch_id() { return last_touch_id_; } - gfx::Point last_touch_location() { - return last_touch_location_; - } + gfx::Point last_touch_location() { return last_touch_location_; } private: + ui::EventTarget* target_; ui::EventType last_touch_type_; int last_touch_id_; gfx::Point last_touch_location_; @@ -53,25 +54,23 @@ class RootWindowEventHandler : public ui::EventHandler { } // namespace -namespace aura { +namespace ash { -typedef test::AuraTestBase WindowTreeHostX11Test; +typedef aura::test::AuraTestBase WindowTreeHostX11Test; // Send X touch events to one WindowTreeHost. The WindowTreeHost's // delegate will get corresponding ui::TouchEvent if the touch events // are winthin the bound of the WindowTreeHost. TEST_F(WindowTreeHostX11Test, DispatchTouchEventToOneRootWindow) { -#if defined(OS_CHROMEOS) // Fake a ChromeOS running env. const char* kLsbRelease = "CHROMEOS_RELEASE_NAME=Chromium OS\n"; base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); -#endif // defined(OS_CHROMEOS) - scoped_ptr<WindowTreeHostX11> window_tree_host( - new WindowTreeHostX11(gfx::Rect(0, 0, 2560, 1700))); + scoped_ptr<AshWindowTreeHostX11> window_tree_host( + new AshWindowTreeHostX11(gfx::Rect(0, 0, 2560, 1700))); window_tree_host->InitHost(); - scoped_ptr<RootWindowEventHandler> handler(new RootWindowEventHandler()); - window_tree_host->window()->AddPreTargetHandler(handler.get()); + scoped_ptr<RootWindowEventHandler> handler( + new RootWindowEventHandler(window_tree_host.get())); std::vector<unsigned int> devices; devices.push_back(0); @@ -82,7 +81,6 @@ TEST_F(WindowTreeHostX11Test, DispatchTouchEventToOneRootWindow) { EXPECT_EQ(-1, handler->last_touch_id()); ui::ScopedXI2Event scoped_xevent; -#if defined(OS_CHROMEOS) // This touch is out of bounds. scoped_xevent.InitTouchEvent( 0, XI_TouchBegin, 5, gfx::Point(1500, 2500), valuators); @@ -90,7 +88,6 @@ TEST_F(WindowTreeHostX11Test, DispatchTouchEventToOneRootWindow) { EXPECT_EQ(ui::ET_UNKNOWN, handler->last_touch_type()); EXPECT_EQ(-1, handler->last_touch_id()); EXPECT_EQ(gfx::Point(0, 0), handler->last_touch_location()); -#endif // defined(OS_CHROMEOS) // Following touchs are within bounds and are passed to delegate. scoped_xevent.InitTouchEvent( @@ -114,36 +111,35 @@ TEST_F(WindowTreeHostX11Test, DispatchTouchEventToOneRootWindow) { EXPECT_EQ(0, handler->last_touch_id()); EXPECT_EQ(gfx::Point(1500, 1600), handler->last_touch_location()); + handler.reset(); + // Revert the CrOS testing env otherwise the following non-CrOS aura // tests will fail. -#if defined(OS_CHROMEOS) // Fake a ChromeOS running env. kLsbRelease = ""; base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); -#endif // defined(OS_CHROMEOS) } // Send X touch events to two WindowTreeHost. The WindowTreeHost which is // the event target of the X touch events should generate the corresponding // ui::TouchEvent for its delegate. -#if defined(OS_CHROMEOS) TEST_F(WindowTreeHostX11Test, DispatchTouchEventToTwoRootWindow) { // Fake a ChromeOS running env. const char* kLsbRelease = "CHROMEOS_RELEASE_NAME=Chromium OS\n"; base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); - scoped_ptr<WindowTreeHostX11> window_tree_host1( - new WindowTreeHostX11(gfx::Rect(0, 0, 2560, 1700))); + scoped_ptr<AshWindowTreeHostX11> window_tree_host1( + new AshWindowTreeHostX11(gfx::Rect(0, 0, 2560, 1700))); window_tree_host1->InitHost(); - scoped_ptr<RootWindowEventHandler> handler1(new RootWindowEventHandler()); - window_tree_host1->window()->AddPreTargetHandler(handler1.get()); + scoped_ptr<RootWindowEventHandler> handler1( + new RootWindowEventHandler(window_tree_host1.get())); int host2_y_offset = 1700; - scoped_ptr<WindowTreeHostX11> window_tree_host2( - new WindowTreeHostX11(gfx::Rect(0, host2_y_offset, 1920, 1080))); + scoped_ptr<AshWindowTreeHostX11> window_tree_host2( + new AshWindowTreeHostX11(gfx::Rect(0, host2_y_offset, 1920, 1080))); window_tree_host2->InitHost(); - scoped_ptr<RootWindowEventHandler> handler2(new RootWindowEventHandler()); - window_tree_host2->window()->AddPreTargetHandler(handler2.get()); + scoped_ptr<RootWindowEventHandler> handler2( + new RootWindowEventHandler(window_tree_host2.get())); std::vector<unsigned int> devices; devices.push_back(0); @@ -216,7 +212,6 @@ TEST_F(WindowTreeHostX11Test, DispatchTouchEventToTwoRootWindow) { EXPECT_EQ(0, handler2->last_touch_id()); EXPECT_EQ(gfx::Point(1500, 2550 - host2_y_offset), handler2->last_touch_location()); - scoped_xevent.InitTouchEvent( 0, XI_TouchEnd, 6, gfx::Point(1600, 2650), valuators); window_tree_host1->DispatchEvent(scoped_xevent); @@ -229,12 +224,14 @@ TEST_F(WindowTreeHostX11Test, DispatchTouchEventToTwoRootWindow) { EXPECT_EQ(gfx::Point(1600, 2650 - host2_y_offset), handler2->last_touch_location()); + handler1.reset(); + handler2.reset(); + // Revert the CrOS testing env otherwise the following non-CrOS aura // tests will fail. // Fake a ChromeOS running env. kLsbRelease = ""; base::SysInfo::SetChromeOSVersionInfoForTest(kLsbRelease, base::Time()); } -#endif // defined(OS_CHROMEOS) } // namespace aura diff --git a/ui/aura/root_window_transformer.h b/ash/host/root_window_transformer.h index 89d67f2..66ebd0b 100644 --- a/ui/aura/root_window_transformer.h +++ b/ash/host/root_window_transformer.h @@ -1,11 +1,11 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright 2014 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 UI_AURA_ROOT_WINDOW_TRANSFORMER_H_ -#define UI_AURA_ROOT_WINDOW_TRANSFORMER_H_ +#ifndef ASH_HOST_ROOT_WINDOW_TRANSFORMER_H_ +#define ASH_HOST_ROOT_WINDOW_TRANSFORMER_H_ -#include "ui/aura/aura_export.h" +#include "ash/ash_export.h" namespace gfx { class Insets; @@ -14,11 +14,11 @@ class Size; class Transform; } -namespace aura { +namespace ash { // RootWindowTransformer controls how RootWindow should be placed and // transformed inside the host window. -class AURA_EXPORT RootWindowTransformer { +class ASH_EXPORT RootWindowTransformer { public: virtual ~RootWindowTransformer() {} @@ -40,6 +40,6 @@ class AURA_EXPORT RootWindowTransformer { virtual gfx::Insets GetHostInsets() const = 0; }; -} // namespace aura +} // namespace ash -#endif // UI_AURA_ROOT_WINDOW_TRANSFORMER_H_ +#endif // ASH_HOST_ROOT_WINDOW_TRANSFORMER_H_ diff --git a/ash/host/transformer_helper.cc b/ash/host/transformer_helper.cc new file mode 100644 index 0000000..f68ffc9 --- /dev/null +++ b/ash/host/transformer_helper.cc @@ -0,0 +1,111 @@ +// Copyright 2014 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/host/transformer_helper.h" + +#include "ash/host/ash_window_tree_host.h" +#include "ash/host/root_window_transformer.h" +#include "ui/aura/window.h" +#include "ui/aura/window_tree_host.h" +#include "ui/compositor/dip_util.h" +#include "ui/gfx/geometry/insets.h" +#include "ui/gfx/geometry/rect.h" +#include "ui/gfx/geometry/rect_f.h" +#include "ui/gfx/geometry/size.h" +#include "ui/gfx/size_conversions.h" +#include "ui/gfx/transform.h" + +namespace ash { +namespace { + +// A simple RootWindowTransformer without host insets. +class SimpleRootWindowTransformer : public RootWindowTransformer { + public: + SimpleRootWindowTransformer(const aura::Window* root_window, + const gfx::Transform& transform) + : root_window_(root_window), transform_(transform) {} + + // RootWindowTransformer overrides: + virtual gfx::Transform GetTransform() const OVERRIDE { return transform_; } + + virtual gfx::Transform GetInverseTransform() const OVERRIDE { + gfx::Transform invert; + if (!transform_.GetInverse(&invert)) + return transform_; + return invert; + } + + virtual gfx::Rect GetRootWindowBounds(const gfx::Size& host_size) const + OVERRIDE { + gfx::Rect bounds(host_size); + gfx::RectF new_bounds(ui::ConvertRectToDIP(root_window_->layer(), bounds)); + transform_.TransformRect(&new_bounds); + return gfx::Rect(gfx::ToFlooredSize(new_bounds.size())); + } + + virtual gfx::Insets GetHostInsets() const OVERRIDE { return gfx::Insets(); } + + private: + virtual ~SimpleRootWindowTransformer() {} + + const aura::Window* root_window_; + const gfx::Transform transform_; + + DISALLOW_COPY_AND_ASSIGN(SimpleRootWindowTransformer); +}; + +} // namespace + +TransformerHelper::TransformerHelper(AshWindowTreeHost* ash_host) + : ash_host_(ash_host) { + SetTransform(gfx::Transform()); +} + +TransformerHelper::~TransformerHelper() {} + +gfx::Insets TransformerHelper::GetHostInsets() const { + return transformer_->GetHostInsets(); +} + +void TransformerHelper::SetTransform(const gfx::Transform& transform) { + scoped_ptr<RootWindowTransformer> transformer(new SimpleRootWindowTransformer( + ash_host_->AsWindowTreeHost()->window(), transform)); + SetRootWindowTransformer(transformer.Pass()); +} + +void TransformerHelper::SetRootWindowTransformer( + scoped_ptr<RootWindowTransformer> transformer) { + transformer_ = transformer.Pass(); + aura::WindowTreeHost* host = ash_host_->AsWindowTreeHost(); + aura::Window* window = host->window(); + window->SetTransform(transformer_->GetTransform()); + // If the layer is not animating, then we need to update the root window + // size immediately. + if (!window->layer()->GetAnimator()->is_animating()) + host->UpdateRootWindowSize(host->GetBounds().size()); +} + +gfx::Transform TransformerHelper::GetTransform() const { + float scale = ui::GetDeviceScaleFactor( + ash_host_->AsWindowTreeHost()->window()->layer()); + gfx::Transform transform; + transform.Scale(scale, scale); + transform *= transformer_->GetTransform(); + return transform; +} + +gfx::Transform TransformerHelper::GetInverseTransform() const { + float scale = ui::GetDeviceScaleFactor( + ash_host_->AsWindowTreeHost()->window()->layer()); + gfx::Transform transform; + transform.Scale(1.0f / scale, 1.0f / scale); + return transformer_->GetInverseTransform() * transform; +} + +void TransformerHelper::UpdateWindowSize(const gfx::Size& host_size) { + ash_host_->AsWindowTreeHost()->window()->SetBounds( + transformer_->GetRootWindowBounds(host_size)); +} + +} // namespace ash diff --git a/ash/host/transformer_helper.h b/ash/host/transformer_helper.h new file mode 100644 index 0000000..d64af80 --- /dev/null +++ b/ash/host/transformer_helper.h @@ -0,0 +1,54 @@ +// Copyright 2014 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_HOST_TRANSFORMER_HELPER_H_ +#define ASH_HOST_TRANSFORMER_HELPER_H_ + +#include "base/memory/scoped_ptr.h" + +namespace gfx { +class Insets; +class Size; +class Transform; +} + +namespace ash { +class AshWindowTreeHost; +class RootWindowTransformer; + +// A helper class to handle ash specific feature that requires +// transforming a root window (such as rotation, UI zooming). +class TransformerHelper { + public: + explicit TransformerHelper(AshWindowTreeHost* ash_host); + ~TransformerHelper(); + + // Returns the the insets that specifies the effective root window + // area within the host window. + gfx::Insets GetHostInsets() const; + + // Sets a simple transform with no host insets. + void SetTransform(const gfx::Transform& transform); + + // Sets a RootWindowTransformer which takes the insets into account. + void SetRootWindowTransformer(scoped_ptr<RootWindowTransformer> transformer); + + // Returns the transforms applied to the root window. + gfx::Transform GetTransform() const; + gfx::Transform GetInverseTransform() const; + + // Updates the root window size based on the host size and + // current transform. + void UpdateWindowSize(const gfx::Size& host_size); + + private: + AshWindowTreeHost* ash_host_; + scoped_ptr<RootWindowTransformer> transformer_; + + DISALLOW_COPY_AND_ASSIGN(TransformerHelper); +}; + +} // namespace ash + +#endif // ASH_HOST_TRANSFORMER_HELPER_H_ diff --git a/ash/host/window_tree_host_factory.cc b/ash/host/window_tree_host_factory.cc deleted file mode 100644 index ddb60d0..0000000 --- a/ash/host/window_tree_host_factory.cc +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2012 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/host/window_tree_host_factory.h" - -#include "ui/aura/window_tree_host.h" - -namespace { - -class WindowTreeHostFactoryImpl : public ash::WindowTreeHostFactory { - public: - WindowTreeHostFactoryImpl() {} - - // Overridden from WindowTreeHostFactory: - virtual aura::WindowTreeHost* CreateWindowTreeHost( - const gfx::Rect& initial_bounds) OVERRIDE { - return aura::WindowTreeHost::Create(initial_bounds); - } -}; - -} - -namespace ash { - -// static -WindowTreeHostFactory* WindowTreeHostFactory::Create() { - return new WindowTreeHostFactoryImpl; -} - -} // namespace ash diff --git a/ash/host/window_tree_host_factory.h b/ash/host/window_tree_host_factory.h deleted file mode 100644 index a17927c..0000000 --- a/ash/host/window_tree_host_factory.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2012 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_HOST_WINDOW_TREE_HOST_FACTORY_H_ -#define ASH_HOST_WINDOW_TREE_HOST_FACTORY_H_ - -#include "ash/ash_export.h" -#include "ui/gfx/rect.h" - -namespace aura { -class WindowTreeHost; -} - -namespace ash { - -class ASH_EXPORT WindowTreeHostFactory { - public: - virtual ~WindowTreeHostFactory() {} - - static WindowTreeHostFactory* Create(); - - // Creates a new aura::WindowTreeHost. The caller owns the returned value. - virtual aura::WindowTreeHost* CreateWindowTreeHost( - const gfx::Rect& initial_bounds) = 0; - - protected: - WindowTreeHostFactory() {} -}; - -} // namespace ash - -#endif // ASH_HOST_WINDOW_TREE_HOST_FACTORY_H_ diff --git a/ash/host/window_tree_host_factory_win.cc b/ash/host/window_tree_host_factory_win.cc deleted file mode 100644 index 42eb753..0000000 --- a/ash/host/window_tree_host_factory_win.cc +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2012 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/host/window_tree_host_factory.h" - -#include "ash/ash_switches.h" -#include "base/command_line.h" -#include "base/win/windows_version.h" -#include "ui/aura/remote_window_tree_host_win.h" -#include "ui/aura/window_tree_host.h" - -namespace { - -class WindowTreeHostFactoryImpl : public ash::WindowTreeHostFactory { - public: - WindowTreeHostFactoryImpl() {} - - // Overridden from WindowTreeHostFactory: - virtual aura::WindowTreeHost* CreateWindowTreeHost( - const gfx::Rect& initial_bounds) OVERRIDE { - if (base::win::GetVersion() >= base::win::VERSION_WIN8 && - !CommandLine::ForCurrentProcess()->HasSwitch( - ash::switches::kForceAshToDesktop)) - return aura::RemoteWindowTreeHostWin::Create(initial_bounds); - - return aura::WindowTreeHost::Create(initial_bounds); - } -}; - -} - -namespace ash { - -// static -WindowTreeHostFactory* WindowTreeHostFactory::Create() { - return new WindowTreeHostFactoryImpl; -} - -} // namespace ash diff --git a/ash/magnifier/DEPS b/ash/magnifier/DEPS new file mode 100644 index 0000000..d7471c3 --- /dev/null +++ b/ash/magnifier/DEPS @@ -0,0 +1,5 @@ +specific_include_rules = { + "magnification_controller\.cc": [ + "+ash/host" + ], +} diff --git a/ash/magnifier/magnification_controller.cc b/ash/magnifier/magnification_controller.cc index 8e13e6b..e5119a9 100644 --- a/ash/magnifier/magnification_controller.cc +++ b/ash/magnifier/magnification_controller.cc @@ -8,12 +8,14 @@ #include "ash/accessibility_delegate.h" #include "ash/ash_switches.h" #include "ash/display/root_window_transformers.h" +#include "ash/host/ash_window_tree_host.h" +#include "ash/host/root_window_transformer.h" +#include "ash/root_window_controller.h" #include "ash/shell.h" #include "ash/system/tray/system_tray_delegate.h" #include "base/command_line.h" #include "base/synchronization/waitable_event.h" #include "ui/aura/client/cursor_client.h" -#include "ui/aura/root_window_transformer.h" #include "ui/aura/window.h" #include "ui/aura/window_property.h" #include "ui/aura/window_tree_host.h" @@ -270,9 +272,10 @@ bool MagnificationControllerImpl::RedrawDIP(const gfx::PointF& position_in_dip, gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow(root_window_); - scoped_ptr<aura::RootWindowTransformer> transformer( + scoped_ptr<RootWindowTransformer> transformer( CreateRootWindowTransformerForDisplay(root_window_, display)); - root_window_->GetHost()->SetRootWindowTransformer(transformer.Pass()); + GetRootWindowController(root_window_)->ash_host()->SetRootWindowTransformer( + transformer.Pass()); if (animate) is_on_animation_ = true; diff --git a/ash/root_window_controller.cc b/ash/root_window_controller.cc index d4878b6..6477b14 100644 --- a/ash/root_window_controller.cc +++ b/ash/root_window_controller.cc @@ -15,6 +15,7 @@ #include "ash/display/display_manager.h" #include "ash/focus_cycler.h" #include "ash/high_contrast/high_contrast_controller.h" +#include "ash/host/ash_window_tree_host.h" #include "ash/root_window_settings.h" #include "ash/session_state_delegate.h" #include "ash/shelf/shelf_layout_manager.h" @@ -258,20 +259,19 @@ class EmptyWindowDelegate : public aura::WindowDelegate { } // namespace -void RootWindowController::CreateForPrimaryDisplay(aura::WindowTreeHost* host) { +void RootWindowController::CreateForPrimaryDisplay(AshWindowTreeHost* host) { RootWindowController* controller = new RootWindowController(host); controller->Init(RootWindowController::PRIMARY, Shell::GetInstance()->delegate()->IsFirstRunAfterBoot()); } -void RootWindowController::CreateForSecondaryDisplay( - aura::WindowTreeHost* host) { +void RootWindowController::CreateForSecondaryDisplay(AshWindowTreeHost* host) { RootWindowController* controller = new RootWindowController(host); controller->Init(RootWindowController::SECONDARY, false /* first run */); } void RootWindowController::CreateForVirtualKeyboardDisplay( - aura::WindowTreeHost* host) { + AshWindowTreeHost* host) { RootWindowController* controller = new RootWindowController(host); controller->Init(RootWindowController::VIRTUAL_KEYBOARD, false /* first run */); @@ -304,12 +304,28 @@ aura::Window* RootWindowController::GetContainerForWindow( RootWindowController::~RootWindowController() { Shutdown(); - host_.reset(); + ash_host_.reset(); // The CaptureClient needs to be around for as long as the RootWindow is // valid. capture_client_.reset(); } +aura::WindowTreeHost* RootWindowController::GetHost() { + return ash_host_->AsWindowTreeHost(); +} + +const aura::WindowTreeHost* RootWindowController::GetHost() const { + return ash_host_->AsWindowTreeHost(); +} + +aura::Window* RootWindowController::GetRootWindow() { + return GetHost()->window(); +} + +const aura::Window* RootWindowController::GetRootWindow() const { + return GetHost()->window(); +} + void RootWindowController::SetWallpaperController( DesktopBackgroundWidgetController* controller) { wallpaper_controller_.reset(controller); @@ -329,29 +345,30 @@ void RootWindowController::Shutdown() { animating_wallpaper_controller_->StopAnimating(); wallpaper_controller_.reset(); animating_wallpaper_controller_.reset(); - + aura::Window* root_window = GetRootWindow(); // Change the target root window before closing child windows. If any child // being removed triggers a relayout of the shelf it will try to build a // window list adding windows from the target root window's containers which // may have already gone away. - if (Shell::GetTargetRootWindow() == root_window()) { + if (Shell::GetTargetRootWindow() == root_window) { Shell::GetInstance()->set_target_root_window( - Shell::GetPrimaryRootWindow() == root_window() ? - NULL : Shell::GetPrimaryRootWindow()); + Shell::GetPrimaryRootWindow() == root_window + ? NULL + : Shell::GetPrimaryRootWindow()); } CloseChildWindows(); - GetRootWindowSettings(root_window())->controller = NULL; + GetRootWindowSettings(root_window)->controller = NULL; screen_dimmer_.reset(); workspace_controller_.reset(); // Forget with the display ID so that display lookup // ends up with invalid display. - GetRootWindowSettings(root_window())->display_id = + GetRootWindowSettings(root_window)->display_id = gfx::Display::kInvalidDisplayID; - GetRootWindowSettings(root_window())->shutdown = true; + GetRootWindowSettings(root_window)->shutdown = true; system_background_.reset(); - aura::client::SetScreenPositionClient(root_window(), NULL); + aura::client::SetScreenPositionClient(root_window, NULL); } SystemModalContainerLayoutManager* @@ -376,11 +393,11 @@ RootWindowController::GetSystemModalLayoutManager(aura::Window* window) { } aura::Window* RootWindowController::GetContainer(int container_id) { - return root_window()->GetChildById(container_id); + return GetRootWindow()->GetChildById(container_id); } const aura::Window* RootWindowController::GetContainer(int container_id) const { - return host_->window()->GetChildById(container_id); + return ash_host_->AsWindowTreeHost()->window()->GetChildById(container_id); } void RootWindowController::ShowShelf() { @@ -464,8 +481,8 @@ void RootWindowController::CloseChildWindows() { docked_layout_manager_->Shutdown(); docked_layout_manager_ = NULL; } - - aura::client::SetDragDropClient(root_window(), NULL); + aura::Window* root_window = GetRootWindow(); + aura::client::SetDragDropClient(root_window, NULL); // TODO(harrym): Remove when Status Area Widget is a child view. if (shelf_) { @@ -480,12 +497,12 @@ void RootWindowController::CloseChildWindows() { animating_wallpaper_controller_.reset(); workspace_controller_.reset(); - aura::client::SetTooltipClient(root_window(), NULL); + aura::client::SetTooltipClient(root_window, NULL); // Explicitly destroy top level windows. We do this as during part of // destruction such windows may query the RootWindow for state. std::queue<aura::Window*> non_toplevel_windows; - non_toplevel_windows.push(root_window()); + non_toplevel_windows.push(root_window); while (!non_toplevel_windows.empty()) { aura::Window* non_toplevel_window = non_toplevel_windows.front(); non_toplevel_windows.pop(); @@ -503,12 +520,12 @@ void RootWindowController::CloseChildWindows() { delete *toplevel_windows.windows().begin(); } // And then remove the containers. - while (!root_window()->children().empty()) { - aura::Window* window = root_window()->children()[0]; + while (!root_window->children().empty()) { + aura::Window* window = root_window->children()[0]; if (window->owned_by_parent()) { delete window; } else { - root_window()->RemoveChild(window); + root_window->RemoveChild(window); } } @@ -519,7 +536,7 @@ void RootWindowController::MoveWindowsTo(aura::Window* dst) { // Forget the shelf early so that shelf don't update itself using wrong // display info. workspace_controller_->SetShelf(NULL); - ReparentAllWindows(root_window(), dst); + ReparentAllWindows(GetRootWindow(), dst); } ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() { @@ -537,9 +554,8 @@ void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen, ui::MenuSourceType source_type) { DCHECK(Shell::GetInstance()->delegate()); scoped_ptr<ui::MenuModel> menu_model( - Shell::GetInstance()->delegate()->CreateContextMenu(root_window(), - NULL, - NULL)); + Shell::GetInstance()->delegate()->CreateContextMenu( + GetRootWindow(), NULL, NULL)); if (!menu_model) return; @@ -567,7 +583,7 @@ void RootWindowController::UpdateShelfVisibility() { const aura::Window* RootWindowController::GetWindowForFullscreenMode() const { const aura::Window* topmost_window = NULL; const aura::Window* active_window = wm::GetActiveWindow(); - if (active_window && active_window->GetRootWindow() == root_window() && + if (active_window && active_window->GetRootWindow() == GetRootWindow() && IsSwitchableContainer(active_window->parent())) { // Use the active window when it is on the current root window to determine // the fullscreen state to allow temporarily using a panel or docked window @@ -631,7 +647,7 @@ void RootWindowController::DeactivateKeyboard( } aura::Window* keyboard_container = keyboard_controller->GetContainerWindow(); - if (keyboard_container->GetRootWindow() == root_window()) { + if (keyboard_container->GetRootWindow() == GetRootWindow()) { aura::Window* parent = GetContainer( kShellWindowId_VirtualKeyboardParentContainer); DCHECK(parent); @@ -657,28 +673,30 @@ bool RootWindowController::IsVirtualKeyboardWindow(aura::Window* window) { //////////////////////////////////////////////////////////////////////////////// // RootWindowController, private: -RootWindowController::RootWindowController(aura::WindowTreeHost* host) - : host_(host), +RootWindowController::RootWindowController(AshWindowTreeHost* ash_host) + : ash_host_(ash_host), root_window_layout_(NULL), docked_layout_manager_(NULL), panel_layout_manager_(NULL), touch_hud_debug_(NULL), touch_hud_projection_(NULL) { - GetRootWindowSettings(root_window())->controller = this; - screen_dimmer_.reset(new ScreenDimmer(root_window())); + aura::Window* root_window = GetRootWindow(); + GetRootWindowSettings(root_window)->controller = this; + screen_dimmer_.reset(new ScreenDimmer(root_window)); stacking_controller_.reset(new StackingController); - aura::client::SetWindowTreeClient(root_window(), stacking_controller_.get()); - capture_client_.reset(new ::wm::ScopedCaptureClient(root_window())); + aura::client::SetWindowTreeClient(root_window, stacking_controller_.get()); + capture_client_.reset(new ::wm::ScopedCaptureClient(root_window)); } void RootWindowController::Init(RootWindowType root_window_type, bool first_run_after_boot) { + aura::Window* root_window = GetRootWindow(); Shell* shell = Shell::GetInstance(); - shell->InitRootWindow(root_window()); + shell->InitRootWindow(root_window); - host_->SetCursor(ui::kCursorPointer); - CreateContainersInRootWindow(root_window()); + ash_host_->AsWindowTreeHost()->SetCursor(ui::kCursorPointer); + CreateContainersInRootWindow(root_window); if (root_window_type == VIRTUAL_KEYBOARD) { shell->InitKeyboard(); @@ -703,9 +721,9 @@ void RootWindowController::Init(RootWindowType root_window_type, shell->InitKeyboard(); } else { root_window_layout()->OnWindowResized(); - shell->desktop_background_controller()->OnRootWindowAdded(root_window()); - shell->high_contrast_controller()->OnRootWindowAdded(root_window()); - host_->Show(); + shell->desktop_background_controller()->OnRootWindowAdded(root_window); + shell->high_contrast_controller()->OnRootWindowAdded(root_window); + ash_host_->AsWindowTreeHost()->Show(); // Create a shelf if a user is already logged in. if (shell->session_state_delegate()->NumberOfLoggedInUsers()) @@ -714,8 +732,9 @@ void RootWindowController::Init(RootWindowType root_window_type, } void RootWindowController::InitLayoutManagers() { - root_window_layout_ = new RootWindowLayoutManager(root_window()); - root_window()->SetLayoutManager(root_window_layout_); + aura::Window* root_window = GetRootWindow(); + root_window_layout_ = new RootWindowLayoutManager(root_window); + root_window->SetLayoutManager(root_window_layout_); aura::Window* default_container = GetContainer(kShellWindowId_DefaultContainer); @@ -767,7 +786,7 @@ void RootWindowController::InitLayoutManagers() { void RootWindowController::InitTouchHuds() { CommandLine* command_line = CommandLine::ForCurrentProcess(); if (command_line->HasSwitch(switches::kAshTouchHud)) - set_touch_hud_debug(new TouchHudDebug(root_window())); + set_touch_hud_debug(new TouchHudDebug(GetRootWindow())); if (Shell::GetInstance()->is_touch_hud_projection_enabled()) EnableTouchHudProjection(); } @@ -780,7 +799,7 @@ void RootWindowController::CreateSystemBackground( color = kChromeOsBootColor; #endif system_background_.reset( - new SystemBackgroundController(root_window(), color)); + new SystemBackgroundController(GetRootWindow(), color)); #if defined(OS_CHROMEOS) // Make a copy of the system's boot splash screen so we can composite it @@ -790,7 +809,7 @@ void RootWindowController::CreateSystemBackground( switches::kAshCopyHostBackgroundAtBoot) || CommandLine::ForCurrentProcess()->HasSwitch( switches::kAshAnimateFromBootSplashScreen))) - boot_splash_screen_.reset(new BootSplashScreen(host())); + boot_splash_screen_.reset(new BootSplashScreen(GetHost())); #endif } @@ -979,7 +998,7 @@ void RootWindowController::CreateContainersInRootWindow( void RootWindowController::EnableTouchHudProjection() { if (touch_hud_projection_) return; - set_touch_hud_projection(new TouchHudProjection(root_window())); + set_touch_hud_projection(new TouchHudProjection(GetRootWindow())); } void RootWindowController::DisableTouchHudProjection() { diff --git a/ash/root_window_controller.h b/ash/root_window_controller.h index e9f6b8e..6199a5c 100644 --- a/ash/root_window_controller.h +++ b/ash/root_window_controller.h @@ -47,6 +47,7 @@ class ScopedCaptureClient; } namespace ash { +class AshWindowTreeHost; class AlwaysOnTopController; class AnimatingDesktopController; class DesktopBackgroundWidgetController; @@ -80,14 +81,14 @@ class ASH_EXPORT RootWindowController : public ShellObserver { public: // Creates and Initialize the RootWindowController for primary display. - static void CreateForPrimaryDisplay(aura::WindowTreeHost* host); + static void CreateForPrimaryDisplay(AshWindowTreeHost* host); // Creates and Initialize the RootWindowController for secondary displays. - static void CreateForSecondaryDisplay(aura::WindowTreeHost* host); + static void CreateForSecondaryDisplay(AshWindowTreeHost* host); // Creates and Initialize the RootWindowController for virtual // keyboard displays. - static void CreateForVirtualKeyboardDisplay(aura::WindowTreeHost* host); + static void CreateForVirtualKeyboardDisplay(AshWindowTreeHost* host); // Returns a RootWindowController that has a shelf for given // |window|. This returns the RootWindowController for the |window|'s @@ -106,10 +107,13 @@ class ASH_EXPORT RootWindowController : public ShellObserver { virtual ~RootWindowController(); - aura::Window* root_window() { return host_->window(); } - const aura::Window* root_window() const { return host_->window(); } - aura::WindowTreeHost* host() { return host_.get(); } - const aura::WindowTreeHost* host() const { return host_.get(); } + AshWindowTreeHost* ash_host() { return ash_host_.get(); } + const AshWindowTreeHost* ash_host() const { return ash_host_.get(); } + + aura::WindowTreeHost* GetHost(); + const aura::WindowTreeHost* GetHost() const; + aura::Window* GetRootWindow(); + const aura::Window* GetRootWindow() const; RootWindowLayoutManager* root_window_layout() { return root_window_layout_; } @@ -235,7 +239,7 @@ class ASH_EXPORT RootWindowController : public ShellObserver { bool IsVirtualKeyboardWindow(aura::Window* window); private: - explicit RootWindowController(aura::WindowTreeHost* host); + explicit RootWindowController(AshWindowTreeHost* host); enum RootWindowType { PRIMARY, SECONDARY, @@ -267,7 +271,7 @@ class ASH_EXPORT RootWindowController : public ShellObserver { virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE; virtual void OnTouchHudProjectionToggled(bool enabled) OVERRIDE; - scoped_ptr<aura::WindowTreeHost> host_; + scoped_ptr<AshWindowTreeHost> ash_host_; RootWindowLayoutManager* root_window_layout_; scoped_ptr<StackingController> stacking_controller_; diff --git a/ash/root_window_controller_unittest.cc b/ash/root_window_controller_unittest.cc index b4fe9f5..69aad6b 100644 --- a/ash/root_window_controller_unittest.cc +++ b/ash/root_window_controller_unittest.cc @@ -292,15 +292,13 @@ TEST_F(RootWindowControllerTest, ModalContainer) { RootWindowController* controller = shell->GetPrimaryRootWindowController(); EXPECT_EQ(user::LOGGED_IN_USER, shell->system_tray_delegate()->GetUserLoginStatus()); - EXPECT_EQ(Shell::GetContainer(controller->root_window(), - kShellWindowId_SystemModalContainer) + EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) ->layout_manager(), controller->GetSystemModalLayoutManager(NULL)); views::Widget* session_modal_widget = CreateModalWidget(gfx::Rect(300, 10, 100, 100)); - EXPECT_EQ(Shell::GetContainer(controller->root_window(), - kShellWindowId_SystemModalContainer) + EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) ->layout_manager(), controller->GetSystemModalLayoutManager( session_modal_widget->GetNativeView())); @@ -308,22 +306,19 @@ TEST_F(RootWindowControllerTest, ModalContainer) { shell->session_state_delegate()->LockScreen(); EXPECT_EQ(user::LOGGED_IN_LOCKED, shell->system_tray_delegate()->GetUserLoginStatus()); - EXPECT_EQ(Shell::GetContainer(controller->root_window(), - kShellWindowId_LockSystemModalContainer) + EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) ->layout_manager(), controller->GetSystemModalLayoutManager(NULL)); - aura::Window* lock_container = Shell::GetContainer( - controller->root_window(), kShellWindowId_LockScreenContainer); + aura::Window* lock_container = + controller->GetContainer(kShellWindowId_LockScreenContainer); views::Widget* lock_modal_widget = CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container); - EXPECT_EQ(Shell::GetContainer(controller->root_window(), - kShellWindowId_LockSystemModalContainer) + EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) ->layout_manager(), controller->GetSystemModalLayoutManager( lock_modal_widget->GetNativeView())); - EXPECT_EQ(Shell::GetContainer(controller->root_window(), - kShellWindowId_SystemModalContainer) + EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) ->layout_manager(), controller->GetSystemModalLayoutManager( session_modal_widget->GetNativeView())); @@ -343,17 +338,15 @@ TEST_F(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) { EXPECT_FALSE(shell->session_state_delegate()->IsActiveUserSessionStarted()); RootWindowController* controller = shell->GetPrimaryRootWindowController(); - EXPECT_EQ(Shell::GetContainer(controller->root_window(), - kShellWindowId_LockSystemModalContainer) + EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) ->layout_manager(), controller->GetSystemModalLayoutManager(NULL)); - aura::Window* lock_container = Shell::GetContainer( - controller->root_window(), kShellWindowId_LockScreenContainer); + aura::Window* lock_container = + controller->GetContainer(kShellWindowId_LockScreenContainer); views::Widget* login_modal_widget = CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container); - EXPECT_EQ(Shell::GetContainer(controller->root_window(), - kShellWindowId_LockSystemModalContainer) + EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) ->layout_manager(), controller->GetSystemModalLayoutManager( login_modal_widget->GetNativeView())); @@ -366,15 +359,13 @@ TEST_F(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) { shell->system_tray_delegate()->GetUserLoginStatus()); EXPECT_EQ(1, shell->session_state_delegate()->NumberOfLoggedInUsers()); EXPECT_TRUE(shell->session_state_delegate()->IsActiveUserSessionStarted()); - EXPECT_EQ(Shell::GetContainer(controller->root_window(), - kShellWindowId_SystemModalContainer) + EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) ->layout_manager(), controller->GetSystemModalLayoutManager(NULL)); views::Widget* session_modal_widget = CreateModalWidget(gfx::Rect(300, 10, 100, 100)); - EXPECT_EQ(Shell::GetContainer(controller->root_window(), - kShellWindowId_SystemModalContainer) + EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) ->layout_manager(), controller->GetSystemModalLayoutManager( session_modal_widget->GetNativeView())); @@ -384,44 +375,39 @@ TEST_F(RootWindowControllerTest, ModalContainerBlockedSession) { UpdateDisplay("600x600"); Shell* shell = Shell::GetInstance(); RootWindowController* controller = shell->GetPrimaryRootWindowController(); - aura::Window* lock_container = Shell::GetContainer( - controller->root_window(), kShellWindowId_LockScreenContainer); + aura::Window* lock_container = + controller->GetContainer(kShellWindowId_LockScreenContainer); for (int block_reason = FIRST_BLOCK_REASON; block_reason < NUMBER_OF_BLOCK_REASONS; ++block_reason) { views::Widget* session_modal_widget = CreateModalWidget(gfx::Rect(300, 10, 100, 100)); - EXPECT_EQ(Shell::GetContainer(controller->root_window(), - kShellWindowId_SystemModalContainer) + EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) ->layout_manager(), controller->GetSystemModalLayoutManager( session_modal_widget->GetNativeView())); - EXPECT_EQ(Shell::GetContainer(controller->root_window(), - kShellWindowId_SystemModalContainer) + EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) ->layout_manager(), controller->GetSystemModalLayoutManager(NULL)); session_modal_widget->Close(); BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); - EXPECT_EQ(Shell::GetContainer(controller->root_window(), - kShellWindowId_LockSystemModalContainer) + EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) ->layout_manager(), controller->GetSystemModalLayoutManager(NULL)); views::Widget* lock_modal_widget = CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container); - EXPECT_EQ(Shell::GetContainer(controller->root_window(), - kShellWindowId_LockSystemModalContainer) + EXPECT_EQ(controller->GetContainer(kShellWindowId_LockSystemModalContainer) ->layout_manager(), controller->GetSystemModalLayoutManager( lock_modal_widget->GetNativeView())); session_modal_widget = CreateModalWidget(gfx::Rect(300, 10, 100, 100)); - EXPECT_EQ(Shell::GetContainer(controller->root_window(), - kShellWindowId_SystemModalContainer) + EXPECT_EQ(controller->GetContainer(kShellWindowId_SystemModalContainer) ->layout_manager(), controller->GetSystemModalLayoutManager( session_modal_widget->GetNativeView())); @@ -479,11 +465,11 @@ TEST_F(RootWindowControllerTest, MultipleDisplaysGetWindowForFullscreenMode) { Widget* w3 = CreateTestWidget(gfx::Rect(600, 0, 100, 100)); EXPECT_EQ(w1->GetNativeWindow()->GetRootWindow(), - controllers[0]->root_window()); + controllers[0]->GetRootWindow()); EXPECT_EQ(w2->GetNativeWindow()->GetRootWindow(), - controllers[0]->root_window()); + controllers[0]->GetRootWindow()); EXPECT_EQ(w3->GetNativeWindow()->GetRootWindow(), - controllers[1]->root_window()); + controllers[1]->GetRootWindow()); w1->Activate(); EXPECT_EQ(NULL, controllers[0]->GetWindowForFullscreenMode()); @@ -508,8 +494,8 @@ TEST_F(RootWindowControllerTest, FocusBlockedWindow) { UpdateDisplay("600x600"); RootWindowController* controller = Shell::GetInstance()->GetPrimaryRootWindowController(); - aura::Window* lock_container = Shell::GetContainer( - controller->root_window(), kShellWindowId_LockScreenContainer); + aura::Window* lock_container = + controller->GetContainer(kShellWindowId_LockScreenContainer); aura::Window* lock_window = Widget::CreateWindowWithParentAndBounds(NULL, lock_container, gfx::Rect(0, 0, 100, 100))->GetNativeView(); lock_window->Show(); diff --git a/ash/shell.cc b/ash/shell.cc index 4617a19..e4dec64 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -30,7 +30,6 @@ #include "ash/frame/custom_frame_view_ash.h" #include "ash/gpu_support.h" #include "ash/high_contrast/high_contrast_controller.h" -#include "ash/host/window_tree_host_factory.h" #include "ash/keyboard_uma_event_filter.h" #include "ash/magnifier/magnification_controller.h" #include "ash/magnifier/partial_magnification_controller.h" @@ -838,10 +837,9 @@ void Shell::Init() { focus_cycler_.reset(new FocusCycler()); screen_position_controller_.reset(new ScreenPositionController); - window_tree_host_factory_.reset(delegate_->CreateWindowTreeHostFactory()); display_controller_->Start(); - display_controller_->InitPrimaryDisplay(); + display_controller_->CreatePrimaryHost(); aura::Window* root_window = display_controller_->GetPrimaryRootWindow(); target_root_window_ = root_window; @@ -977,12 +975,7 @@ void Shell::Init() { base::Unretained(system_tray_delegate_.get())))); #endif - // TODO(oshima): Initialize all RootWindowControllers once, and - // initialize controller/delegates above when initializing the - // primary root window controller. - RootWindowController::CreateForPrimaryDisplay(root_window->GetHost()); - - display_controller_->InitSecondaryDisplays(); + display_controller_->InitDisplays(); // It needs to be created after RootWindowController has been created // (which calls OnWindowResized has been called, otherwise the diff --git a/ash/shell.h b/ash/shell.h index 3a29e29e..ba9ddfd 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -145,7 +145,6 @@ class WebNotificationTray; class WindowCycleController; class WindowPositioner; class WindowSelectorController; -class WindowTreeHostFactory; namespace shell { class WindowWatcher; @@ -515,10 +514,6 @@ class ASH_EXPORT Shell : public SystemModalContainerEventFilterDelegate, } #endif // defined(OS_CHROMEOS) - WindowTreeHostFactory* window_tree_host_factory() { - return window_tree_host_factory_.get(); - } - ShelfModel* shelf_model() { return shelf_model_.get(); } @@ -652,12 +647,12 @@ class ASH_EXPORT Shell : public SystemModalContainerEventFilterDelegate, scoped_ptr<AutoclickController> autoclick_controller_; scoped_ptr<aura::client::FocusClient> focus_client_; aura::client::ActivationClient* activation_client_; + scoped_ptr<MouseCursorEventFilter> mouse_cursor_filter_; scoped_ptr<ScreenPositionController> screen_position_controller_; scoped_ptr<SystemModalContainerEventFilter> modality_filter_; scoped_ptr<EventClientImpl> event_client_; scoped_ptr<EventTransformationHandler> event_transformation_handler_; - scoped_ptr<WindowTreeHostFactory> window_tree_host_factory_; // An event filter that pre-handles key events while the partial // screenshot UI or the keyboard overlay is active. diff --git a/ash/shell/shell_delegate_impl.cc b/ash/shell/shell_delegate_impl.cc index dfae093..840c6bb 100644 --- a/ash/shell/shell_delegate_impl.cc +++ b/ash/shell/shell_delegate_impl.cc @@ -8,7 +8,6 @@ #include "ash/default_accessibility_delegate.h" #include "ash/default_user_wallpaper_delegate.h" #include "ash/gpu_support_stub.h" -#include "ash/host/window_tree_host_factory.h" #include "ash/media_delegate.h" #include "ash/new_window_delegate.h" #include "ash/session_state_delegate.h" @@ -172,10 +171,6 @@ ui::MenuModel* ShellDelegateImpl::CreateContextMenu( return new ContextMenu(root); } -WindowTreeHostFactory* ShellDelegateImpl::CreateWindowTreeHostFactory() { - return WindowTreeHostFactory::Create(); -} - GPUSupport* ShellDelegateImpl::CreateGPUSupport() { // Real GPU support depends on src/content, so just use a stub. return new GPUSupportStub; diff --git a/ash/shell/shell_delegate_impl.h b/ash/shell/shell_delegate_impl.h index 5da2060..ede6820 100644 --- a/ash/shell/shell_delegate_impl.h +++ b/ash/shell/shell_delegate_impl.h @@ -62,7 +62,6 @@ class ShellDelegateImpl : public ash::ShellDelegate { aura::Window* root_window, ash::ShelfItemDelegate* item_delegate, ash::ShelfItem* item) OVERRIDE; - virtual WindowTreeHostFactory* CreateWindowTreeHostFactory() OVERRIDE; virtual GPUSupport* CreateGPUSupport() OVERRIDE; virtual base::string16 GetProductName() const OVERRIDE; diff --git a/ash/shell_delegate.h b/ash/shell_delegate.h index eaca177..d41132b 100644 --- a/ash/shell_delegate.h +++ b/ash/shell_delegate.h @@ -42,7 +42,6 @@ namespace ash { class AccessibilityDelegate; class MediaDelegate; class NewWindowDelegate; -class WindowTreeHostFactory; class SessionStateDelegate; class ShelfDelegate; class ShelfItemDelegate; @@ -146,10 +145,6 @@ class ASH_EXPORT ShellDelegate { ash::ShelfItemDelegate* item_delegate, ash::ShelfItem* item) = 0; - // Creates a root window host factory. Shell takes ownership of the returned - // value. - virtual WindowTreeHostFactory* CreateWindowTreeHostFactory() = 0; - // Creates a GPU support object. Shell takes ownership of the object. virtual GPUSupport* CreateGPUSupport() = 0; diff --git a/ash/test/DEPS b/ash/test/DEPS index e6be49d..7d7a2ec 100644 --- a/ash/test/DEPS +++ b/ash/test/DEPS @@ -4,3 +4,12 @@ include_rules = [ "+content/public/test/test_browser_context.h", "+win8/viewer", ] + +specific_include_rules = { + "ash_test_helper\.cc": [ + "+ash/host" + ], + "mirror_window_test_api\.cc": [ + "+ash/host" + ], +} diff --git a/ash/test/mirror_window_test_api.cc b/ash/test/mirror_window_test_api.cc index 701b27e..4941038 100644 --- a/ash/test/mirror_window_test_api.cc +++ b/ash/test/mirror_window_test_api.cc @@ -7,16 +7,19 @@ #include "ash/display/cursor_window_controller.h" #include "ash/display/display_controller.h" #include "ash/display/mirror_window_controller.h" +#include "ash/host/root_window_transformer.h" #include "ash/shell.h" -#include "ui/aura/root_window_transformer.h" #include "ui/gfx/point.h" namespace ash { namespace test { const aura::WindowTreeHost* MirrorWindowTestApi::GetHost() const { - return Shell::GetInstance()->display_controller()-> - mirror_window_controller()->host_.get(); + aura::Window* window = Shell::GetInstance() + ->display_controller() + ->mirror_window_controller() + ->GetWindow(); + return window ? window->GetHost() : NULL; } int MirrorWindowTestApi::GetCurrentCursorType() const { @@ -34,7 +37,7 @@ const aura::Window* MirrorWindowTestApi::GetCursorWindow() const { cursor_window_controller()->cursor_window_.get(); } -scoped_ptr<aura::RootWindowTransformer> +scoped_ptr<RootWindowTransformer> MirrorWindowTestApi::CreateCurrentRootWindowTransformer() const { return Shell::GetInstance()->display_controller()-> mirror_window_controller()->CreateRootWindowTransformer(); diff --git a/ash/test/mirror_window_test_api.h b/ash/test/mirror_window_test_api.h index bef8a9f..ce58f97 100644 --- a/ash/test/mirror_window_test_api.h +++ b/ash/test/mirror_window_test_api.h @@ -9,7 +9,6 @@ #include "base/memory/scoped_ptr.h" namespace aura { -class RootWindowTransformer; class Window; class WindowTreeHost; } @@ -19,6 +18,8 @@ class Point; } namespace ash { +class RootWindowTransformer; + namespace test { class MirrorWindowTestApi { @@ -32,8 +33,7 @@ class MirrorWindowTestApi { const gfx::Point& GetCursorHotPoint() const; const aura::Window* GetCursorWindow() const; - scoped_ptr<aura::RootWindowTransformer> - CreateCurrentRootWindowTransformer() const; + scoped_ptr<RootWindowTransformer> CreateCurrentRootWindowTransformer() const; private: DISALLOW_COPY_AND_ASSIGN(MirrorWindowTestApi); diff --git a/ash/test/test_shell_delegate.cc b/ash/test/test_shell_delegate.cc index d2eeb10..8ba5ba0 100644 --- a/ash/test/test_shell_delegate.cc +++ b/ash/test/test_shell_delegate.cc @@ -8,7 +8,6 @@ #include "ash/default_accessibility_delegate.h" #include "ash/gpu_support_stub.h" -#include "ash/host/window_tree_host_factory.h" #include "ash/media_delegate.h" #include "ash/new_window_delegate.h" #include "ash/session_state_delegate.h" @@ -153,10 +152,6 @@ ui::MenuModel* TestShellDelegate::CreateContextMenu( return NULL; } -WindowTreeHostFactory* TestShellDelegate::CreateWindowTreeHostFactory() { - return WindowTreeHostFactory::Create(); -} - GPUSupport* TestShellDelegate::CreateGPUSupport() { // Real GPU support depends on src/content, so just use a stub. return new GPUSupportStub; diff --git a/ash/test/test_shell_delegate.h b/ash/test/test_shell_delegate.h index b5d17df..1d8da2f 100644 --- a/ash/test/test_shell_delegate.h +++ b/ash/test/test_shell_delegate.h @@ -58,7 +58,6 @@ class TestShellDelegate : public ShellDelegate { aura::Window* root, ash::ShelfItemDelegate* item_delegate, ash::ShelfItem* item) OVERRIDE; - virtual WindowTreeHostFactory* CreateWindowTreeHostFactory() OVERRIDE; virtual GPUSupport* CreateGPUSupport() OVERRIDE; virtual base::string16 GetProductName() const OVERRIDE; diff --git a/ash/wm/maximize_mode/maximize_mode_window_manager.cc b/ash/wm/maximize_mode/maximize_mode_window_manager.cc index eb133f7..9de08eb 100644 --- a/ash/wm/maximize_mode/maximize_mode_window_manager.cc +++ b/ash/wm/maximize_mode/maximize_mode_window_manager.cc @@ -211,7 +211,7 @@ void MaximizeModeWindowManager::EnableBackdropBehindTopWindowOnEachDisplay( iter != controllers.end(); ++iter) { RootWindowController* controller = *iter; aura::Window* container = Shell::GetContainer( - controller->root_window(), kShellWindowId_DefaultContainer); + controller->GetRootWindow(), kShellWindowId_DefaultContainer); controller->workspace_controller()->SetMaximizeBackdropDelegate( scoped_ptr<WorkspaceLayoutManagerDelegate>( enable ? new WorkspaceBackdropDelegate(container) : NULL)); diff --git a/ash/wm/window_manager_unittest.cc b/ash/wm/window_manager_unittest.cc index a94395f..cc1a675 100644 --- a/ash/wm/window_manager_unittest.cc +++ b/ash/wm/window_manager_unittest.cc @@ -604,7 +604,7 @@ TEST_F(WindowManagerTest, MAYBE_TransformActivate) { gfx::Transform transform; transform.Translate(size.width(), 0); transform.Rotate(90.0f); - root_window->GetHost()->SetTransform(transform); + root_window->GetHost()->SetRootTransform(transform); test::TestActivationDelegate d1; aura::test::TestWindowDelegate wd; diff --git a/chrome/browser/metro_viewer/chrome_metro_viewer_process_host_aurawin.cc b/chrome/browser/metro_viewer/chrome_metro_viewer_process_host_aurawin.cc index 3f12f08..ee614c1 100644 --- a/chrome/browser/metro_viewer/chrome_metro_viewer_process_host_aurawin.cc +++ b/chrome/browser/metro_viewer/chrome_metro_viewer_process_host_aurawin.cc @@ -6,6 +6,7 @@ #include "ash/display/display_info.h" #include "ash/display/display_manager.h" +#include "ash/host/ash_remote_window_tree_host_win.h" #include "ash/shell.h" #include "ash/wm/window_positioner.h" #include "base/logging.h" @@ -117,8 +118,10 @@ void ChromeMetroViewerProcessHost::OnChannelConnected(int32 /*peer_pid*/) { void ChromeMetroViewerProcessHost::OnSetTargetSurface( gfx::NativeViewId target_surface) { HWND hwnd = reinterpret_cast<HWND>(target_surface); + // Make hwnd available as early as possible for proper InputMethod // initialization. + ash::AshRemoteWindowTreeHostWin::Init(); aura::RemoteWindowTreeHostWin::Instance()->SetRemoteWindowHandle(hwnd); // Now start the Ash shell environment. diff --git a/chrome/browser/ui/ash/chrome_shell_delegate.cc b/chrome/browser/ui/ash/chrome_shell_delegate.cc index 8a3aacd..2307885 100644 --- a/chrome/browser/ui/ash/chrome_shell_delegate.cc +++ b/chrome/browser/ui/ash/chrome_shell_delegate.cc @@ -7,7 +7,6 @@ #include "apps/app_window.h" #include "apps/app_window_registry.h" #include "ash/content_support/gpu_support_impl.h" -#include "ash/host/window_tree_host_factory.h" #include "ash/magnifier/magnifier_constants.h" #include "ash/wm/window_state.h" #include "ash/wm/window_util.h" @@ -144,10 +143,6 @@ ui::MenuModel* ChromeShellDelegate::CreateContextMenu( return new LauncherContextMenu(shelf_delegate_, root); } -ash::WindowTreeHostFactory* ChromeShellDelegate::CreateWindowTreeHostFactory() { - return ash::WindowTreeHostFactory::Create(); -} - ash::GPUSupport* ChromeShellDelegate::CreateGPUSupport() { // Chrome uses real GPU support. return new ash::GPUSupportImpl; diff --git a/chrome/browser/ui/ash/chrome_shell_delegate.h b/chrome/browser/ui/ash/chrome_shell_delegate.h index 8c960c6..577b28e 100644 --- a/chrome/browser/ui/ash/chrome_shell_delegate.h +++ b/chrome/browser/ui/ash/chrome_shell_delegate.h @@ -76,7 +76,6 @@ class ChromeShellDelegate : public ash::ShellDelegate, aura::Window* root, ash::ShelfItemDelegate* item_delegate, ash::ShelfItem* item) OVERRIDE; - virtual ash::WindowTreeHostFactory* CreateWindowTreeHostFactory() OVERRIDE; virtual ash::GPUSupport* CreateGPUSupport() OVERRIDE; virtual base::string16 GetProductName() const OVERRIDE; diff --git a/mojo/examples/aura_demo/window_tree_host_mojo.cc b/mojo/examples/aura_demo/window_tree_host_mojo.cc index b266ca9..7a5bd4e 100644 --- a/mojo/examples/aura_demo/window_tree_host_mojo.cc +++ b/mojo/examples/aura_demo/window_tree_host_mojo.cc @@ -71,10 +71,6 @@ void WindowTreeHostMojo::Hide() { window()->Hide(); } -void WindowTreeHostMojo::ToggleFullScreen() { - NOTIMPLEMENTED(); -} - gfx::Rect WindowTreeHostMojo::GetBounds() const { return bounds_; } @@ -84,15 +80,6 @@ void WindowTreeHostMojo::SetBounds(const gfx::Rect& bounds) { native_viewport_->SetBounds(bounds); } -gfx::Insets WindowTreeHostMojo::GetInsets() const { - NOTIMPLEMENTED(); - return gfx::Insets(); -} - -void WindowTreeHostMojo::SetInsets(const gfx::Insets& insets) { - NOTIMPLEMENTED(); -} - gfx::Point WindowTreeHostMojo::GetLocationOnNativeScreen() const { return gfx::Point(0, 0); } @@ -110,15 +97,6 @@ bool WindowTreeHostMojo::QueryMouseLocation(gfx::Point* location_return) { return false; } -bool WindowTreeHostMojo::ConfineCursorToRootWindow() { - NOTIMPLEMENTED(); - return false; -} - -void WindowTreeHostMojo::UnConfineCursor() { - NOTIMPLEMENTED(); -} - void WindowTreeHostMojo::PostNativeEvent( const base::NativeEvent& native_event) { NOTIMPLEMENTED(); diff --git a/mojo/examples/aura_demo/window_tree_host_mojo.h b/mojo/examples/aura_demo/window_tree_host_mojo.h index 538c16d..80d178c 100644 --- a/mojo/examples/aura_demo/window_tree_host_mojo.h +++ b/mojo/examples/aura_demo/window_tree_host_mojo.h @@ -36,17 +36,12 @@ class WindowTreeHostMojo : public aura::WindowTreeHost, virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; - virtual void ToggleFullScreen() OVERRIDE; virtual gfx::Rect GetBounds() const OVERRIDE; virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; - virtual gfx::Insets GetInsets() const OVERRIDE; - virtual void SetInsets(const gfx::Insets& insets) OVERRIDE; virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; virtual void SetCapture() OVERRIDE; virtual void ReleaseCapture() OVERRIDE; virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE; - virtual bool ConfineCursorToRootWindow() OVERRIDE; - virtual void UnConfineCursor() OVERRIDE; virtual void PostNativeEvent(const base::NativeEvent& native_event) OVERRIDE; virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; virtual void SetCursorNative(gfx::NativeCursor cursor) OVERRIDE; diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp index 9a910a2..f49a294 100644 --- a/ui/aura/aura.gyp +++ b/ui/aura/aura.gyp @@ -63,9 +63,8 @@ 'input_state_lookup_win.h', 'layout_manager.cc', 'layout_manager.h', - 'remote_window_tree_host_win.cc', + 'remote_window_tree_host_win.cc', 'remote_window_tree_host_win.h', - 'root_window_transformer.h', 'scoped_window_targeter.cc', 'scoped_window_targeter.h', 'window.cc', @@ -117,7 +116,6 @@ ['use_x11==1', { 'dependencies': [ '../../build/linux/system.gyp:x11', - '../../build/linux/system.gyp:xfixes', '../../build/linux/system.gyp:xrandr', '../../build/linux/system.gyp:xi', ], @@ -261,7 +259,6 @@ ], 'sources': [ 'gestures/gesture_recognizer_unittest.cc', - 'window_tree_host_x11_unittest.cc', 'window_event_dispatcher_unittest.cc', 'test/run_all_unittests.cc', 'window_targeter_unittest.cc', diff --git a/ui/aura/remote_window_tree_host_win.cc b/ui/aura/remote_window_tree_host_win.cc index 19715ba..6525588 100644 --- a/ui/aura/remote_window_tree_host_win.cc +++ b/ui/aura/remote_window_tree_host_win.cc @@ -149,16 +149,17 @@ void HandleMetroExit() { RemoteWindowTreeHostWin* g_instance = NULL; +// static RemoteWindowTreeHostWin* RemoteWindowTreeHostWin::Instance() { - if (g_instance) - return g_instance; - return Create(gfx::Rect()); + if (!g_instance) + g_instance = new RemoteWindowTreeHostWin(gfx::Rect()); + return g_instance; } -RemoteWindowTreeHostWin* RemoteWindowTreeHostWin::Create( - const gfx::Rect& bounds) { - g_instance = g_instance ? g_instance : new RemoteWindowTreeHostWin(bounds); - return g_instance; +// static +void RemoteWindowTreeHostWin::SetInstance(RemoteWindowTreeHostWin* instance) { + CHECK(!g_instance); + g_instance = instance; } RemoteWindowTreeHostWin::RemoteWindowTreeHostWin(const gfx::Rect& bounds) @@ -390,9 +391,6 @@ void RemoteWindowTreeHostWin::Hide() { NOTIMPLEMENTED(); } -void RemoteWindowTreeHostWin::ToggleFullScreen() { -} - gfx::Rect RemoteWindowTreeHostWin::GetBounds() const { return gfx::Rect(window_size_); } @@ -402,13 +400,6 @@ void RemoteWindowTreeHostWin::SetBounds(const gfx::Rect& bounds) { OnHostResized(bounds.size()); } -gfx::Insets RemoteWindowTreeHostWin::GetInsets() const { - return gfx::Insets(); -} - -void RemoteWindowTreeHostWin::SetInsets(const gfx::Insets& insets) { -} - gfx::Point RemoteWindowTreeHostWin::GetLocationOnNativeScreen() const { return gfx::Point(0, 0); } @@ -433,13 +424,6 @@ bool RemoteWindowTreeHostWin::QueryMouseLocation(gfx::Point* location_return) { return true; } -bool RemoteWindowTreeHostWin::ConfineCursorToRootWindow() { - return true; -} - -void RemoteWindowTreeHostWin::UnConfineCursor() { -} - void RemoteWindowTreeHostWin::SetCursorNative(gfx::NativeCursor native_cursor) { if (!host_) return; diff --git a/ui/aura/remote_window_tree_host_win.h b/ui/aura/remote_window_tree_host_win.h index c873963..887f01f 100644 --- a/ui/aura/remote_window_tree_host_win.h +++ b/ui/aura/remote_window_tree_host_win.h @@ -107,9 +107,14 @@ class AURA_EXPORT RemoteWindowTreeHostWin public ui::internal::RemoteInputMethodDelegateWin { public: // Returns the only RemoteWindowTreeHostWin, if this is the first time - // this function is called, it will call Create() wiht empty bounds. + // this function is called and the instance have never set by SetInstance, + // it will call Create() wiht empty bounds. static RemoteWindowTreeHostWin* Instance(); - static RemoteWindowTreeHostWin* Create(const gfx::Rect& bounds); + + // Manually sets the instance to be used as a return value of |Instance()| + // method above. This should not be called if the instance has already + // been set or created, and doing so will result in CHECK failure. + static void SetInstance(RemoteWindowTreeHostWin* instance); // Returns true if there is a RemoteWindowTreeHostWin and it has a valid // HWND. A return value of false typically indicates we're not in metro mode. @@ -171,10 +176,11 @@ class AURA_EXPORT RemoteWindowTreeHostWin // OS. bool IsForegroundWindow(); - private: + protected: explicit RemoteWindowTreeHostWin(const gfx::Rect& bounds); virtual ~RemoteWindowTreeHostWin(); + private: // IPC message handing methods: void OnMouseMoved(int32 x, int32 y, int32 flags); void OnMouseButton(const MetroViewerHostMsg_MouseButtonParams& params); @@ -219,17 +225,12 @@ class AURA_EXPORT RemoteWindowTreeHostWin virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; - virtual void ToggleFullScreen() OVERRIDE; virtual gfx::Rect GetBounds() const OVERRIDE; virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; - virtual gfx::Insets GetInsets() const OVERRIDE; - virtual void SetInsets(const gfx::Insets& insets) OVERRIDE; virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; virtual void SetCapture() OVERRIDE; virtual void ReleaseCapture() OVERRIDE; virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE; - virtual bool ConfineCursorToRootWindow() OVERRIDE; - virtual void UnConfineCursor() OVERRIDE; virtual void PostNativeEvent(const base::NativeEvent& native_event) OVERRIDE; virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; virtual void SetCursorNative(gfx::NativeCursor cursor) OVERRIDE; diff --git a/ui/aura/test/test_screen.cc b/ui/aura/test/test_screen.cc index e5158ae..425f58e 100644 --- a/ui/aura/test/test_screen.cc +++ b/ui/aura/test/test_screen.cc @@ -48,7 +48,7 @@ void TestScreen::SetDeviceScaleFactor(float device_scale_factor) { void TestScreen::SetDisplayRotation(gfx::Display::Rotation rotation) { display_.set_rotation(rotation); // TODO(oshima|mukai): Update the display_ as well. - host_->SetTransform(GetRotationTransform() * GetUIScaleTransform()); + host_->SetRootTransform(GetRotationTransform() * GetUIScaleTransform()); } void TestScreen::SetUIScale(float ui_scale) { @@ -57,7 +57,7 @@ void TestScreen::SetUIScale(float ui_scale) { gfx::Rect new_bounds = gfx::ToNearestRect( gfx::ScaleRect(bounds_in_pixel, 1.0f / ui_scale)); display_.SetScaleAndBounds(display_.device_scale_factor(), new_bounds); - host_->SetTransform(GetRotationTransform() * GetUIScaleTransform()); + host_->SetRootTransform(GetRotationTransform() * GetUIScaleTransform()); } gfx::Transform TestScreen::GetRotationTransform() const { diff --git a/ui/aura/window_tree_host.cc b/ui/aura/window_tree_host.cc index 9c3cf12..a88d9a0 100644 --- a/ui/aura/window_tree_host.cc +++ b/ui/aura/window_tree_host.cc @@ -8,7 +8,6 @@ #include "ui/aura/client/capture_client.h" #include "ui/aura/client/cursor_client.h" #include "ui/aura/env.h" -#include "ui/aura/root_window_transformer.h" #include "ui/aura/window.h" #include "ui/aura/window_event_dispatcher.h" #include "ui/aura/window_targeter.h" @@ -36,47 +35,6 @@ float GetDeviceScaleFactorFromDisplay(Window* window) { return display.device_scale_factor(); } -class SimpleRootWindowTransformer : public RootWindowTransformer { - public: - SimpleRootWindowTransformer(const Window* root_window, - const gfx::Transform& transform) - : root_window_(root_window), - transform_(transform) { - } - - // RootWindowTransformer overrides: - virtual gfx::Transform GetTransform() const OVERRIDE { - return transform_; - } - - virtual gfx::Transform GetInverseTransform() const OVERRIDE { - gfx::Transform invert; - if (!transform_.GetInverse(&invert)) - return transform_; - return invert; - } - - virtual gfx::Rect GetRootWindowBounds( - const gfx::Size& host_size) const OVERRIDE { - gfx::Rect bounds(host_size); - gfx::RectF new_bounds(ui::ConvertRectToDIP(root_window_->layer(), bounds)); - transform_.TransformRect(&new_bounds); - return gfx::Rect(gfx::ToFlooredSize(new_bounds.size())); - } - - virtual gfx::Insets GetHostInsets() const OVERRIDE { - return gfx::Insets(); - } - - private: - virtual ~SimpleRootWindowTransformer() {} - - const Window* root_window_; - const gfx::Transform transform_; - - DISALLOW_COPY_AND_ASSIGN(SimpleRootWindowTransformer); -}; - //////////////////////////////////////////////////////////////////////////////// // WindowTreeHost, public: @@ -113,8 +71,6 @@ void WindowTreeHost::InitCompositor() { compositor_->SetScaleAndSize(GetDeviceScaleFactorFromDisplay(window()), GetBounds().size()); compositor_->SetRootLayer(window()->layer()); - transformer_.reset( - new SimpleRootWindowTransformer(window(), gfx::Transform())); } void WindowTreeHost::AddObserver(WindowTreeHostObserver* observer) { @@ -129,40 +85,32 @@ ui::EventProcessor* WindowTreeHost::event_processor() { return dispatcher(); } -void WindowTreeHost::SetRootWindowTransformer( - scoped_ptr<RootWindowTransformer> transformer) { - transformer_ = transformer.Pass(); - SetInsets(transformer_->GetHostInsets()); - window()->SetTransform(transformer_->GetTransform()); - // If the layer is not animating, then we need to update the root window - // size immediately. - if (!window()->layer()->GetAnimator()->is_animating()) - UpdateRootWindowSize(GetBounds().size()); -} - gfx::Transform WindowTreeHost::GetRootTransform() const { float scale = ui::GetDeviceScaleFactor(window()->layer()); gfx::Transform transform; transform.Scale(scale, scale); - transform *= transformer_->GetTransform(); + transform *= window()->layer()->transform(); return transform; } -void WindowTreeHost::SetTransform(const gfx::Transform& transform) { - scoped_ptr<RootWindowTransformer> transformer( - new SimpleRootWindowTransformer(window(), transform)); - SetRootWindowTransformer(transformer.Pass()); +void WindowTreeHost::SetRootTransform(const gfx::Transform& transform) { + window()->SetTransform(transform); + UpdateRootWindowSize(GetBounds().size()); } gfx::Transform WindowTreeHost::GetInverseRootTransform() const { - float scale = ui::GetDeviceScaleFactor(window()->layer()); - gfx::Transform transform; - transform.Scale(1.0f / scale, 1.0f / scale); - return transformer_->GetInverseTransform() * transform; + gfx::Transform invert; + gfx::Transform transform = GetRootTransform(); + if (!transform.GetInverse(&invert)) + return transform; + return invert; } void WindowTreeHost::UpdateRootWindowSize(const gfx::Size& host_size) { - window()->SetBounds(transformer_->GetRootWindowBounds(host_size)); + gfx::Rect bounds(host_size); + gfx::RectF new_bounds(ui::ConvertRectToDIP(window()->layer(), bounds)); + GetRootTransform().TransformRect(&new_bounds); + window()->SetBounds(gfx::Rect(gfx::ToFlooredSize(new_bounds.size()))); } void WindowTreeHost::ConvertPointToNativeScreen(gfx::Point* point) const { diff --git a/ui/aura/window_tree_host.h b/ui/aura/window_tree_host.h index ca4a164..55d119e 100644 --- a/ui/aura/window_tree_host.h +++ b/ui/aura/window_tree_host.h @@ -28,7 +28,6 @@ class ViewProp; } namespace aura { -class RootWindowTransformer; class WindowEventDispatcher; class WindowTreeHostObserver; @@ -66,16 +65,14 @@ class AURA_EXPORT WindowTreeHost { ui::Compositor* compositor() { return compositor_.get(); } - void SetRootWindowTransformer(scoped_ptr<RootWindowTransformer> transformer); - gfx::Transform GetRootTransform() const; - - void SetTransform(const gfx::Transform& transform); - - gfx::Transform GetInverseRootTransform() const; + // Gets/Sets the root window's transform. + virtual gfx::Transform GetRootTransform() const; + virtual void SetRootTransform(const gfx::Transform& transform); + virtual gfx::Transform GetInverseRootTransform() const; // Updates the root window's size using |host_size|, current // transform and insets. - void UpdateRootWindowSize(const gfx::Size& host_size); + virtual void UpdateRootWindowSize(const gfx::Size& host_size); // Returns the actual size of the screen. // (gfx::Screen only reports on the virtual desktop exposed by Aura.) @@ -123,18 +120,10 @@ class AURA_EXPORT WindowTreeHost { // Hides the WindowTreeHost. virtual void Hide() = 0; - // Toggles the host's full screen state. - virtual void ToggleFullScreen() = 0; - // Gets/Sets the size of the WindowTreeHost. virtual gfx::Rect GetBounds() const = 0; virtual void SetBounds(const gfx::Rect& bounds) = 0; - // Sets/Gets the insets that specifies the effective root window area - // in the host window. - virtual gfx::Insets GetInsets() const = 0; - virtual void SetInsets(const gfx::Insets& insets) = 0; - // Sets the OS capture to the root window. virtual void SetCapture() = 0; @@ -149,14 +138,6 @@ class AURA_EXPORT WindowTreeHost { // This method is expensive, instead use gfx::Screen::GetCursorScreenPoint(). virtual bool QueryMouseLocation(gfx::Point* location_return) = 0; - // Clips the cursor to the bounds of the root window until UnConfineCursor(). - // We would like to be able to confine the cursor to that window. However, - // currently, we do not have such functionality in X. So we just confine - // to the root window. This is ok because this option is currently only - // being used in fullscreen mode, so root_window bounds = window bounds. - virtual bool ConfineCursorToRootWindow() = 0; - virtual void UnConfineCursor() = 0; - // Posts |native_event| to the platform's event queue. virtual void PostNativeEvent(const base::NativeEvent& native_event) = 0; @@ -208,8 +189,6 @@ class AURA_EXPORT WindowTreeHost { scoped_ptr<ui::Compositor> compositor_; - scoped_ptr<RootWindowTransformer> transformer_; - // Last cursor set. Used for testing. gfx::NativeCursor last_cursor_; diff --git a/ui/aura/window_tree_host_ozone.cc b/ui/aura/window_tree_host_ozone.cc index 0a01e42..6216440 100644 --- a/ui/aura/window_tree_host_ozone.cc +++ b/ui/aura/window_tree_host_ozone.cc @@ -59,20 +59,12 @@ void WindowTreeHostOzone::Show() { NOTIMPLEMENTED(); } void WindowTreeHostOzone::Hide() { NOTIMPLEMENTED(); } -void WindowTreeHostOzone::ToggleFullScreen() { NOTIMPLEMENTED(); } - gfx::Rect WindowTreeHostOzone::GetBounds() const { return bounds_; } void WindowTreeHostOzone::SetBounds(const gfx::Rect& bounds) { NOTIMPLEMENTED(); } -gfx::Insets WindowTreeHostOzone::GetInsets() const { return gfx::Insets(); } - -void WindowTreeHostOzone::SetInsets(const gfx::Insets& insets) { - NOTIMPLEMENTED(); -} - gfx::Point WindowTreeHostOzone::GetLocationOnNativeScreen() const { return bounds_.origin(); } @@ -86,13 +78,6 @@ bool WindowTreeHostOzone::QueryMouseLocation(gfx::Point* location_return) { return false; } -bool WindowTreeHostOzone::ConfineCursorToRootWindow() { - NOTIMPLEMENTED(); - return false; -} - -void WindowTreeHostOzone::UnConfineCursor() { NOTIMPLEMENTED(); } - void WindowTreeHostOzone::PostNativeEvent( const base::NativeEvent& native_event) { NOTIMPLEMENTED(); diff --git a/ui/aura/window_tree_host_ozone.h b/ui/aura/window_tree_host_ozone.h index 0e1f469..0a32da5 100644 --- a/ui/aura/window_tree_host_ozone.h +++ b/ui/aura/window_tree_host_ozone.h @@ -32,17 +32,12 @@ class WindowTreeHostOzone : public WindowTreeHost, virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; - virtual void ToggleFullScreen() OVERRIDE; virtual gfx::Rect GetBounds() const OVERRIDE; virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; - virtual gfx::Insets GetInsets() const OVERRIDE; - virtual void SetInsets(const gfx::Insets& bounds) OVERRIDE; virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; virtual void SetCapture() OVERRIDE; virtual void ReleaseCapture() OVERRIDE; virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE; - virtual bool ConfineCursorToRootWindow() OVERRIDE; - virtual void UnConfineCursor() OVERRIDE; virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE; virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; virtual void SetCursorNative(gfx::NativeCursor cursor_type) OVERRIDE; diff --git a/ui/aura/window_tree_host_win.cc b/ui/aura/window_tree_host_win.cc index 28bd77d..5f1dc00 100644 --- a/ui/aura/window_tree_host_win.cc +++ b/ui/aura/window_tree_host_win.cc @@ -41,10 +41,7 @@ gfx::Size WindowTreeHost::GetNativeScreenSize() { } WindowTreeHostWin::WindowTreeHostWin(const gfx::Rect& bounds) - : fullscreen_(false), - has_capture_(false), - saved_window_style_(0), - saved_window_ex_style_(0) { + : has_capture_(false) { if (use_popup_as_root_window_for_test) set_window_style(WS_POPUP); Init(NULL, bounds); @@ -70,38 +67,6 @@ void WindowTreeHostWin::Hide() { NOTIMPLEMENTED(); } -void WindowTreeHostWin::ToggleFullScreen() { - gfx::Rect target_rect; - if (!fullscreen_) { - fullscreen_ = true; - saved_window_style_ = GetWindowLong(hwnd(), GWL_STYLE); - saved_window_ex_style_ = GetWindowLong(hwnd(), GWL_EXSTYLE); - GetWindowRect(hwnd(), &saved_window_rect_); - SetWindowLong(hwnd(), GWL_STYLE, - saved_window_style_ & ~(WS_CAPTION | WS_THICKFRAME)); - SetWindowLong(hwnd(), GWL_EXSTYLE, - saved_window_ex_style_ & ~(WS_EX_DLGMODALFRAME | - WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE)); - - MONITORINFO mi; - mi.cbSize = sizeof(mi); - GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTONEAREST), &mi); - target_rect = gfx::Rect(mi.rcMonitor); - } else { - fullscreen_ = false; - SetWindowLong(hwnd(), GWL_STYLE, saved_window_style_); - SetWindowLong(hwnd(), GWL_EXSTYLE, saved_window_ex_style_); - target_rect = gfx::Rect(saved_window_rect_); - } - SetWindowPos(hwnd(), - NULL, - target_rect.x(), - target_rect.y(), - target_rect.width(), - target_rect.height(), - SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); -} - gfx::Rect WindowTreeHostWin::GetBounds() const { RECT r; GetClientRect(hwnd(), &r); @@ -109,11 +74,6 @@ gfx::Rect WindowTreeHostWin::GetBounds() const { } void WindowTreeHostWin::SetBounds(const gfx::Rect& bounds) { - if (fullscreen_) { - saved_window_rect_.right = saved_window_rect_.left + bounds.width(); - saved_window_rect_.bottom = saved_window_rect_.top + bounds.height(); - return; - } RECT window_rect; window_rect.left = bounds.x(); window_rect.top = bounds.y(); @@ -141,13 +101,6 @@ void WindowTreeHostWin::SetBounds(const gfx::Rect& bounds) { OnHostResized(bounds.size()); } -gfx::Insets WindowTreeHostWin::GetInsets() const { - return gfx::Insets(); -} - -void WindowTreeHostWin::SetInsets(const gfx::Insets& insets) { -} - gfx::Point WindowTreeHostWin::GetLocationOnNativeScreen() const { RECT r; GetClientRect(hwnd(), &r); @@ -187,16 +140,6 @@ bool WindowTreeHostWin::QueryMouseLocation(gfx::Point* location_return) { pt.y >= 0 && static_cast<int>(pt.y) < size.height()); } -bool WindowTreeHostWin::ConfineCursorToRootWindow() { - RECT window_rect; - GetWindowRect(hwnd(), &window_rect); - return ClipCursor(&window_rect) != 0; -} - -void WindowTreeHostWin::UnConfineCursor() { - ClipCursor(NULL); -} - void WindowTreeHostWin::SetCursorNative(gfx::NativeCursor native_cursor) { // Custom web cursors are handled directly. if (native_cursor == ui::kCursorCustom) diff --git a/ui/aura/window_tree_host_win.h b/ui/aura/window_tree_host_win.h index 1d2f256..dc5f46c 100644 --- a/ui/aura/window_tree_host_win.h +++ b/ui/aura/window_tree_host_win.h @@ -13,27 +13,22 @@ namespace aura { -class WindowTreeHostWin : public WindowTreeHost, - public ui::EventSource, - public gfx::WindowImpl { +class AURA_EXPORT WindowTreeHostWin : public WindowTreeHost, + public ui::EventSource, + public gfx::WindowImpl { public: - WindowTreeHostWin(const gfx::Rect& bounds); + explicit WindowTreeHostWin(const gfx::Rect& bounds); virtual ~WindowTreeHostWin(); // WindowTreeHost: virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; - virtual void ToggleFullScreen() OVERRIDE; virtual gfx::Rect GetBounds() const OVERRIDE; virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; - virtual gfx::Insets GetInsets() const OVERRIDE; - virtual void SetInsets(const gfx::Insets& insets) OVERRIDE; virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; virtual void SetCapture() OVERRIDE; virtual void ReleaseCapture() OVERRIDE; virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE; - virtual bool ConfineCursorToRootWindow() OVERRIDE; - virtual void UnConfineCursor() OVERRIDE; virtual void SetCursorNative(gfx::NativeCursor cursor) OVERRIDE; virtual void MoveCursorToNative(const gfx::Point& location) OVERRIDE; virtual void OnCursorVisibilityChangedNative(bool show) OVERRIDE; @@ -79,11 +74,7 @@ class WindowTreeHostWin : public WindowTreeHost, void OnPaint(HDC dc); void OnSize(UINT param, const gfx::Size& size); - bool fullscreen_; bool has_capture_; - RECT saved_window_rect_; - DWORD saved_window_style_; - DWORD saved_window_ex_style_; DISALLOW_COPY_AND_ASSIGN(WindowTreeHostWin); }; diff --git a/ui/aura/window_tree_host_x11.cc b/ui/aura/window_tree_host_x11.cc index 1858858..22b0bfe 100644 --- a/ui/aura/window_tree_host_x11.cc +++ b/ui/aura/window_tree_host_x11.cc @@ -6,7 +6,6 @@ #include <strings.h> #include <X11/cursorfont.h> -#include <X11/extensions/Xfixes.h> #include <X11/extensions/XInput2.h> #include <X11/extensions/Xrandr.h> #include <X11/Xatom.h> @@ -26,8 +25,8 @@ #include "base/strings/stringprintf.h" #include "base/sys_info.h" #include "ui/aura/client/cursor_client.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/base/cursor/cursor.h" #include "ui/base/ui_base_switches.h" @@ -40,7 +39,6 @@ #include "ui/events/event_switches.h" #include "ui/events/event_utils.h" #include "ui/events/keycodes/keyboard_codes.h" -#include "ui/events/platform/platform_event_observer.h" #include "ui/events/platform/x11/x11_event_source.h" #include "ui/events/x/device_data_manager.h" #include "ui/events/x/device_list_cache_x.h" @@ -108,137 +106,6 @@ bool default_override_redirect = false; } // namespace -namespace internal { - -// Accomplishes 2 tasks concerning touch event calibration: -// 1. Being a message-pump observer, -// routes all the touch events to the X root window, -// where they can be calibrated later. -// 2. Has the Calibrate method that does the actual bezel calibration, -// when invoked from X root window's event dispatcher. -class TouchEventCalibrate : public ui::PlatformEventObserver { - public: - TouchEventCalibrate() - : left_(0), - right_(0), - top_(0), - bottom_(0) { - if (ui::PlatformEventSource::GetInstance()) - ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); -#if defined(USE_XI2_MT) - std::vector<std::string> parts; - if (Tokenize(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( - switches::kTouchCalibration), ",", &parts) >= 4) { - if (!base::StringToInt(parts[0], &left_)) - DLOG(ERROR) << "Incorrect left border calibration value passed."; - if (!base::StringToInt(parts[1], &right_)) - DLOG(ERROR) << "Incorrect right border calibration value passed."; - if (!base::StringToInt(parts[2], &top_)) - DLOG(ERROR) << "Incorrect top border calibration value passed."; - if (!base::StringToInt(parts[3], &bottom_)) - DLOG(ERROR) << "Incorrect bottom border calibration value passed."; - } -#endif // defined(USE_XI2_MT) - } - - virtual ~TouchEventCalibrate() { - if (ui::PlatformEventSource::GetInstance()) - ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this); - } - - // Modify the location of the |event|, - // expanding it from |bounds| to (|bounds| + bezels). - // Required when touchscreen is bigger than screen (i.e. has bezels), - // because we receive events in touchscreen coordinates, - // which need to be expanded when converting to screen coordinates, - // so that location on bezels will be outside of screen area. - void Calibrate(ui::TouchEvent* event, const gfx::Rect& bounds) { -#if defined(USE_XI2_MT) - int x = event->x(); - int y = event->y(); - - if (!left_ && !right_ && !top_ && !bottom_) - return; - - const int resolution_x = bounds.width(); - const int resolution_y = bounds.height(); - // The "grace area" (10% in this case) is to make it easier for the user to - // navigate to the corner. - const double kGraceAreaFraction = 0.1; - if (left_ || right_) { - // Offset the x position to the real - x -= left_; - // Check if we are in the grace area of the left side. - // Note: We might not want to do this when the gesture is locked? - if (x < 0 && x > -left_ * kGraceAreaFraction) - x = 0; - // Check if we are in the grace area of the right side. - // Note: We might not want to do this when the gesture is locked? - if (x > resolution_x - left_ && - x < resolution_x - left_ + right_ * kGraceAreaFraction) - x = resolution_x - left_; - // Scale the screen area back to the full resolution of the screen. - x = (x * resolution_x) / (resolution_x - (right_ + left_)); - } - if (top_ || bottom_) { - // When there is a top bezel we add our border, - y -= top_; - - // Check if we are in the grace area of the top side. - // Note: We might not want to do this when the gesture is locked? - if (y < 0 && y > -top_ * kGraceAreaFraction) - y = 0; - - // Check if we are in the grace area of the bottom side. - // Note: We might not want to do this when the gesture is locked? - if (y > resolution_y - top_ && - y < resolution_y - top_ + bottom_ * kGraceAreaFraction) - y = resolution_y - top_; - // Scale the screen area back to the full resolution of the screen. - y = (y * resolution_y) / (resolution_y - (bottom_ + top_)); - } - - // Set the modified coordinate back to the event. - if (event->root_location() == event->location()) { - // Usually those will be equal, - // if not, I am not sure what the correct value should be. - event->set_root_location(gfx::Point(x, y)); - } - event->set_location(gfx::Point(x, y)); -#endif // defined(USE_XI2_MT) - } - - private: - // ui::PlatformEventObserver: - virtual void WillProcessEvent(const ui::PlatformEvent& event) OVERRIDE { -#if defined(USE_XI2_MT) - if (event->type == GenericEvent && - (event->xgeneric.evtype == XI_TouchBegin || - event->xgeneric.evtype == XI_TouchUpdate || - event->xgeneric.evtype == XI_TouchEnd)) { - XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(event->xcookie.data); - xievent->event = xievent->root; - xievent->event_x = xievent->root_x; - xievent->event_y = xievent->root_y; - } -#endif // defined(USE_XI2_MT) - } - - virtual void DidProcessEvent(const ui::PlatformEvent& event) OVERRIDE {} - - // The difference in screen's native resolution pixels between - // the border of the touchscreen and the border of the screen, - // aka bezel sizes. - int left_; - int right_; - int top_; - int bottom_; - - DISALLOW_COPY_AND_ASSIGN(TouchEventCalibrate); -}; - -} // namespace internal - //////////////////////////////////////////////////////////////////////////////// // WindowTreeHostX11 @@ -249,8 +116,6 @@ WindowTreeHostX11::WindowTreeHostX11(const gfx::Rect& bounds) current_cursor_(ui::kCursorNull), window_mapped_(false), bounds_(bounds), - is_internal_display_(false), - touch_calibrate_(new internal::TouchEventCalibrate), atom_cache_(xdisplay_, kAtomsToCache) { XSetWindowAttributes swa; memset(&swa, 0, sizeof(swa)); @@ -309,17 +174,13 @@ WindowTreeHostX11::WindowTreeHostX11(const gfx::Rect& bounds) XRRSelectInput(xdisplay_, x_root_window_, RRScreenChangeNotifyMask | RROutputChangeNotifyMask); - Env::GetInstance()->AddObserver(this); CreateCompositor(GetAcceleratedWidget()); } WindowTreeHostX11::~WindowTreeHostX11() { - Env::GetInstance()->RemoveObserver(this); if (ui::PlatformEventSource::GetInstance()) ui::PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); - UnConfineCursor(); - DestroyCompositor(); DestroyDispatcher(); XDestroyWindow(xdisplay_, xwindow_); @@ -352,12 +213,12 @@ uint32_t WindowTreeHostX11::DispatchEvent(const ui::PlatformEvent& event) { // EnterNotify creates ET_MOUSE_MOVE. Mark as synthesized as this is not // real mouse move event. mouse_event.set_flags(mouse_event.flags() | ui::EF_IS_SYNTHESIZED); - TranslateAndDispatchMouseEvent(&mouse_event); + TranslateAndDispatchLocatedEvent(&mouse_event); break; } case LeaveNotify: { ui::MouseEvent mouse_event(xev); - TranslateAndDispatchMouseEvent(&mouse_event); + TranslateAndDispatchLocatedEvent(&mouse_event); break; } case Expose: { @@ -381,13 +242,13 @@ uint32_t WindowTreeHostX11::DispatchEvent(const ui::PlatformEvent& event) { switch (ui::EventTypeFromNative(xev)) { case ui::ET_MOUSEWHEEL: { ui::MouseWheelEvent mouseev(xev); - TranslateAndDispatchMouseEvent(&mouseev); + TranslateAndDispatchLocatedEvent(&mouseev); break; } case ui::ET_MOUSE_PRESSED: case ui::ET_MOUSE_RELEASED: { ui::MouseEvent mouseev(xev); - TranslateAndDispatchMouseEvent(&mouseev); + TranslateAndDispatchLocatedEvent(&mouseev); break; } case ui::ET_UNKNOWN: @@ -413,13 +274,7 @@ uint32_t WindowTreeHostX11::DispatchEvent(const ui::PlatformEvent& event) { bool size_changed = bounds_.size() != bounds.size(); bool origin_changed = bounds_.origin() != bounds.origin(); bounds_ = bounds; - UpdateIsInternalDisplay(); - // Always update barrier and mouse location because |bounds_| might - // have already been updated in |SetBounds|. - if (pointer_barriers_) { - UnConfineCursor(); - ConfineCursorToRootWindow(); - } + OnConfigureNotify(); if (size_changed) OnHostResized(bounds.size()); if (origin_changed) @@ -480,7 +335,7 @@ uint32_t WindowTreeHostX11::DispatchEvent(const ui::PlatformEvent& event) { } ui::MouseEvent mouseev(xev); - TranslateAndDispatchMouseEvent(&mouseev); + TranslateAndDispatchLocatedEvent(&mouseev); break; } } @@ -522,10 +377,6 @@ void WindowTreeHostX11::Hide() { } } -void WindowTreeHostX11::ToggleFullScreen() { - NOTIMPLEMENTED(); -} - gfx::Rect WindowTreeHostX11::GetBounds() const { return bounds_; } @@ -561,7 +412,6 @@ void WindowTreeHostX11::SetBounds(const gfx::Rect& bounds) { // (possibly synthetic) ConfigureNotify about the actual size and correct // |bounds_| later. bounds_ = bounds; - UpdateIsInternalDisplay(); if (origin_changed) OnHostMoved(bounds.origin()); if (size_changed || current_scale != new_scale) { @@ -571,18 +421,6 @@ void WindowTreeHostX11::SetBounds(const gfx::Rect& bounds) { } } -gfx::Insets WindowTreeHostX11::GetInsets() const { - return insets_; -} - -void WindowTreeHostX11::SetInsets(const gfx::Insets& insets) { - insets_ = insets; - if (pointer_barriers_) { - UnConfineCursor(); - ConfineCursorToRootWindow(); - } -} - gfx::Point WindowTreeHostX11::GetLocationOnNativeScreen() const { return bounds_.origin(); } @@ -619,54 +457,6 @@ bool WindowTreeHostX11::QueryMouseLocation(gfx::Point* location_return) { win_y_return >= 0 && win_y_return < bounds_.height()); } -bool WindowTreeHostX11::ConfineCursorToRootWindow() { -#if XFIXES_MAJOR >= 5 - DCHECK(!pointer_barriers_.get()); - if (pointer_barriers_) - return false; - pointer_barriers_.reset(new XID[4]); - gfx::Rect bounds(bounds_); - bounds.Inset(insets_); - // Horizontal, top barriers. - pointer_barriers_[0] = XFixesCreatePointerBarrier( - xdisplay_, x_root_window_, - bounds.x(), bounds.y(), bounds.right(), bounds.y(), - BarrierPositiveY, - 0, XIAllDevices); - // Horizontal, bottom barriers. - pointer_barriers_[1] = XFixesCreatePointerBarrier( - xdisplay_, x_root_window_, - bounds.x(), bounds.bottom(), bounds.right(), bounds.bottom(), - BarrierNegativeY, - 0, XIAllDevices); - // Vertical, left barriers. - pointer_barriers_[2] = XFixesCreatePointerBarrier( - xdisplay_, x_root_window_, - bounds.x(), bounds.y(), bounds.x(), bounds.bottom(), - BarrierPositiveX, - 0, XIAllDevices); - // Vertical, right barriers. - pointer_barriers_[3] = XFixesCreatePointerBarrier( - xdisplay_, x_root_window_, - bounds.right(), bounds.y(), bounds.right(), bounds.bottom(), - BarrierNegativeX, - 0, XIAllDevices); -#endif - return true; -} - -void WindowTreeHostX11::UnConfineCursor() { -#if XFIXES_MAJOR >= 5 - if (pointer_barriers_) { - XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[0]); - XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[1]); - XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[2]); - XFixesDestroyPointerBarrier(xdisplay_, pointer_barriers_[3]); - pointer_barriers_.reset(); - } -#endif -} - void WindowTreeHostX11::PostNativeEvent( const base::NativeEvent& native_event) { DCHECK(xwindow_); @@ -718,25 +508,6 @@ void WindowTreeHostX11::MoveCursorToNative(const gfx::Point& location) { } void WindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) { - SetCrOSTapPaused(!show); -} - -void WindowTreeHostX11::OnWindowInitialized(Window* window) { -} - -void WindowTreeHostX11::OnHostInitialized(WindowTreeHost* host) { - // TODO(beng): I'm not sure that this comment makes much sense anymore?? - // UpdateIsInternalDisplay relies on WED's kDisplayIdKey property being set - // available by the time WED::Init is called. (set in - // DisplayManager::CreateRootWindowForDisplay) - // Ready when NotifyHostInitialized is called from WED::Init. - if (host != this) - return; - UpdateIsInternalDisplay(); - - // We have to enable Tap-to-click by default because the cursor is set to - // visible in Shell::InitRootWindowController. - SetCrOSTapPaused(false); } ui::EventProcessor* WindowTreeHostX11::GetEventProcessor() { @@ -772,26 +543,11 @@ void WindowTreeHostX11::DispatchXI2Event(const base::NativeEvent& event) { // RootWindow will cause problem. So only generate the ui::TouchEvent // when we are sure it belongs to this RootWindow. if (base::SysInfo::IsRunningOnChromeOS() && - !bounds_.Contains(ui::EventLocationFromNative(xev))) - break; -#endif // defined(OS_CHROMEOS) + !bounds().Contains(ui::EventLocationFromNative(xev))) + return; +#endif ui::TouchEvent touchev(xev); -#if defined(OS_CHROMEOS) - if (base::SysInfo::IsRunningOnChromeOS()) { - // X maps the touch-surface to the size of the X root-window. - // In multi-monitor setup, Coordinate Transformation Matrix - // repositions the touch-surface onto part of X root-window - // containing aura root-window corresponding to the touchscreen. - // However, if aura root-window has non-zero origin, - // we need to relocate the event into aura root-window coordinates. - touchev.Relocate(bounds_.origin()); -#if defined(USE_XI2_MT) - if (is_internal_display_) - touch_calibrate_->Calibrate(&touchev, bounds_); -#endif // defined(USE_XI2_MT) - } -#endif // defined(OS_CHROMEOS) - SendEventToProcessor(&touchev); + TranslateAndDispatchLocatedEvent(&touchev); break; } case ui::ET_MOUSE_MOVED: @@ -808,12 +564,12 @@ void WindowTreeHostX11::DispatchXI2Event(const base::NativeEvent& event) { xev = &last_event; } ui::MouseEvent mouseev(xev); - TranslateAndDispatchMouseEvent(&mouseev); + TranslateAndDispatchLocatedEvent(&mouseev); break; } case ui::ET_MOUSEWHEEL: { ui::MouseWheelEvent mouseev(xev); - TranslateAndDispatchMouseEvent(&mouseev); + TranslateAndDispatchLocatedEvent(&mouseev); break; } case ui::ET_SCROLL_FLING_START: @@ -847,63 +603,11 @@ void WindowTreeHostX11::SetCursorInternal(gfx::NativeCursor cursor) { XDefineCursor(xdisplay_, xwindow_, cursor.platform()); } -void WindowTreeHostX11::TranslateAndDispatchMouseEvent( - ui::MouseEvent* event) { - Window* root_window = window(); - client::ScreenPositionClient* screen_position_client = - client::GetScreenPositionClient(root_window); - gfx::Rect local(bounds_.size()); - - if (screen_position_client && !local.Contains(event->location())) { - gfx::Point location(event->location()); - // In order to get the correct point in screen coordinates - // during passive grab, we first need to find on which host window - // the mouse is on, and find out the screen coordinates on that - // host window, then convert it back to this host window's coordinate. - screen_position_client->ConvertHostPointToScreen(root_window, &location); - screen_position_client->ConvertPointFromScreen(root_window, &location); - ConvertPointToHost(&location); - event->set_location(location); - event->set_root_location(location); - } - SendEventToProcessor(event); -} +void WindowTreeHostX11::OnConfigureNotify() {} -void WindowTreeHostX11::UpdateIsInternalDisplay() { - Window* root_window = window(); - gfx::Screen* screen = gfx::Screen::GetScreenFor(root_window); - gfx::Display display = screen->GetDisplayNearestWindow(root_window); - is_internal_display_ = display.IsInternal(); -} - -void WindowTreeHostX11::SetCrOSTapPaused(bool state) { -#if defined(OS_CHROMEOS) - if (!ui::IsXInput2Available()) - return; - // Temporarily pause tap-to-click when the cursor is hidden. - Atom prop = atom_cache_.GetAtom("Tap Paused"); - unsigned char value = state; - XIDeviceList dev_list = - ui::DeviceListCacheX::GetInstance()->GetXI2DeviceList(xdisplay_); - - // Only slave pointer devices could possibly have tap-paused property. - for (int i = 0; i < dev_list.count; i++) { - if (dev_list[i].use == XISlavePointer) { - Atom old_type; - int old_format; - unsigned long old_nvalues, bytes; - unsigned char* data; - int result = XIGetProperty(xdisplay_, dev_list[i].deviceid, prop, 0, 0, - False, AnyPropertyType, &old_type, &old_format, - &old_nvalues, &bytes, &data); - if (result != Success) - continue; - XFree(data); - XIChangeProperty(xdisplay_, dev_list[i].deviceid, prop, XA_INTEGER, 8, - PropModeReplace, &value, 1); - } - } -#endif +void WindowTreeHostX11::TranslateAndDispatchLocatedEvent( + ui::LocatedEvent* event) { + SendEventToProcessor(event); } // static diff --git a/ui/aura/window_tree_host_x11.h b/ui/aura/window_tree_host_x11.h index 36ecc19..69a7368 100644 --- a/ui/aura/window_tree_host_x11.h +++ b/ui/aura/window_tree_host_x11.h @@ -5,24 +5,20 @@ #ifndef UI_AURA_WINDOW_TREE_HOST_X11_H_ #define UI_AURA_WINDOW_TREE_HOST_X11_H_ -#include <X11/Xlib.h> - -#include <vector> - -// Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. -#undef RootWindow - #include "base/memory/scoped_ptr.h" #include "ui/aura/aura_export.h" -#include "ui/aura/env_observer.h" #include "ui/aura/window_tree_host.h" -#include "ui/base/x/x11_util.h" #include "ui/events/event_source.h" #include "ui/events/platform/platform_event_dispatcher.h" #include "ui/gfx/insets.h" #include "ui/gfx/rect.h" #include "ui/gfx/x/x11_atom_cache.h" +// X forward decls to avoid including Xlib.h in a header file. +typedef struct _XDisplay XDisplay; +typedef unsigned long XID; +typedef XID Window; + namespace ui { class MouseEvent; } @@ -35,8 +31,8 @@ class TouchEventCalibrate; class AURA_EXPORT WindowTreeHostX11 : public WindowTreeHost, public ui::EventSource, - public ui::PlatformEventDispatcher, - public EnvObserver { + public ui::PlatformEventDispatcher { + public: explicit WindowTreeHostX11(const gfx::Rect& bounds); virtual ~WindowTreeHostX11(); @@ -49,30 +45,34 @@ class AURA_EXPORT WindowTreeHostX11 : public WindowTreeHost, virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; - virtual void ToggleFullScreen() OVERRIDE; virtual gfx::Rect GetBounds() const OVERRIDE; virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; - virtual gfx::Insets GetInsets() const OVERRIDE; - virtual void SetInsets(const gfx::Insets& insets) OVERRIDE; virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; virtual void SetCapture() OVERRIDE; virtual void ReleaseCapture() OVERRIDE; virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE; - virtual bool ConfineCursorToRootWindow() OVERRIDE; - virtual void UnConfineCursor() OVERRIDE; virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE; virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; virtual void SetCursorNative(gfx::NativeCursor cursor_type) OVERRIDE; virtual void MoveCursorToNative(const gfx::Point& location) OVERRIDE; virtual void OnCursorVisibilityChangedNative(bool show) OVERRIDE; - // EnvObserver overrides. - virtual void OnWindowInitialized(Window* window) OVERRIDE; - virtual void OnHostInitialized(WindowTreeHost* host) OVERRIDE; - // ui::EventSource overrides. virtual ui::EventProcessor* GetEventProcessor() OVERRIDE; + protected: + // Called when X Configure Notify event is recevied. + virtual void OnConfigureNotify(); + + // Translates the native mouse location into screen coordinates and and + // dispatches the event via WindowEventDispatcher. + virtual void TranslateAndDispatchLocatedEvent(ui::LocatedEvent* event); + + ::Window x_root_window() { return x_root_window_; } + XDisplay* xdisplay() { return xdisplay_; } + const gfx::Rect bounds() const { return bounds_; } + ui::X11AtomCache* atom_cache() { return &atom_cache_; } + private: // Dispatches XI2 events. Note that some events targetted for the X root // window are dispatched to the aura root window (e.g. touch events after @@ -88,17 +88,6 @@ class AURA_EXPORT WindowTreeHostX11 : public WindowTreeHost, // |current_cursor_|. void SetCursorInternal(gfx::NativeCursor cursor); - // Translates the native mouse location into screen coordinates and and - // dispatches the event via WindowEventDispatcher. - void TranslateAndDispatchMouseEvent(ui::MouseEvent* event); - - // Update is_internal_display_ based on delegate_ state - void UpdateIsInternalDisplay(); - - // Set the CrOS touchpad "tap paused" property. It is used to temporarily - // turn off the Tap-to-click feature when the mouse pointer is invisible. - void SetCrOSTapPaused(bool state); - // The display and the native X window hosting the root window. XDisplay* xdisplay_; ::Window xwindow_; @@ -115,16 +104,6 @@ class AURA_EXPORT WindowTreeHostX11 : public WindowTreeHost, // The bounds of |xwindow_|. gfx::Rect bounds_; - // The insets that specifies the effective area within the |window_|. - gfx::Insets insets_; - - // True if the root host resides on the internal display - bool is_internal_display_; - - scoped_ptr<XID[]> pointer_barriers_; - - scoped_ptr<internal::TouchEventCalibrate> touch_calibrate_; - ui::X11AtomCache atom_cache_; DISALLOW_COPY_AND_ASSIGN(WindowTreeHostX11); diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc index 986929b..be2257c 100644 --- a/ui/aura/window_unittest.cc +++ b/ui/aura/window_unittest.cc @@ -370,7 +370,7 @@ TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { transform.Translate(100.0, 100.0); transform.Rotate(90.0); transform.Scale(2.0, 5.0); - host()->SetTransform(transform); + host()->SetRootTransform(transform); host()->MoveCursorTo(gfx::Point(10, 10)); #if !defined(OS_WIN) gfx::Point mouse_location; @@ -451,7 +451,7 @@ TEST_F(WindowTest, MoveCursorToWithComplexTransform) { transform.Translate(10.0, 20.0); transform.Rotate(10.0); transform.Scale(0.3f, 0.5f); - host()->SetTransform(root_transform); + host()->SetRootTransform(root_transform); w1->SetTransform(transform); w11->SetTransform(transform); w111->SetTransform(transform); @@ -1494,7 +1494,7 @@ TEST_F(WindowTest, Transform) { gfx::Transform transform; transform.Translate(size.height(), 0); transform.Rotate(90.0); - host()->SetTransform(transform); + host()->SetRootTransform(transform); // The size should be the transformed size. gfx::Size transformed_size(size.height(), size.width()); @@ -1521,7 +1521,7 @@ TEST_F(WindowTest, TransformGesture) { gfx::Transform transform; transform.Translate(size.height(), 0.0); transform.Rotate(90.0); - host()->SetTransform(transform); + host()->SetRootTransform(transform); ui::TouchEvent press( ui::ET_TOUCH_PRESSED, gfx::Point(size.height() - 10, 10), 0, getTime()); diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc index 2fc499b..ebbd14b 100644 --- a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc +++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc @@ -449,10 +449,6 @@ void DesktopWindowTreeHostWin::Hide() { message_handler_->Hide(); } -void DesktopWindowTreeHostWin::ToggleFullScreen() { - SetWindowTransparency(); -} - // GetBounds and SetBounds work in pixel coordinates, whereas other get/set // methods work in DIP. @@ -500,13 +496,6 @@ void DesktopWindowTreeHostWin::SetBounds(const gfx::Rect& bounds) { HandleClientSizeChanged(new_expanded.size()); } -gfx::Insets DesktopWindowTreeHostWin::GetInsets() const { - return gfx::Insets(); -} - -void DesktopWindowTreeHostWin::SetInsets(const gfx::Insets& insets) { -} - gfx::Point DesktopWindowTreeHostWin::GetLocationOnNativeScreen() const { return GetBounds().origin(); } @@ -533,16 +522,6 @@ bool DesktopWindowTreeHostWin::QueryMouseLocation(gfx::Point* location_return) { return true; } -bool DesktopWindowTreeHostWin::ConfineCursorToRootWindow() { - RECT window_rect = window()->GetBoundsInScreen().ToRECT(); - ::ClipCursor(&window_rect); - return true; -} - -void DesktopWindowTreeHostWin::UnConfineCursor() { - ::ClipCursor(NULL); -} - void DesktopWindowTreeHostWin::PostNativeEvent( const base::NativeEvent& native_event) { } diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.h b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.h index dc8a218..95044e3 100644 --- a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.h +++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.h @@ -109,17 +109,12 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; - virtual void ToggleFullScreen() OVERRIDE; virtual gfx::Rect GetBounds() const OVERRIDE; virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; - virtual gfx::Insets GetInsets() const OVERRIDE; - virtual void SetInsets(const gfx::Insets& insets) OVERRIDE; virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; virtual void SetCapture() OVERRIDE; virtual void ReleaseCapture() OVERRIDE; virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE; - virtual bool ConfineCursorToRootWindow() OVERRIDE; - virtual void UnConfineCursor() OVERRIDE; virtual void PostNativeEvent(const base::NativeEvent& native_event) OVERRIDE; virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; virtual void SetCursorNative(gfx::NativeCursor cursor) OVERRIDE; diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc index 028b6f5..ed7ca42 100644 --- a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc +++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc @@ -762,10 +762,6 @@ void DesktopWindowTreeHostX11::Hide() { native_widget_delegate_->OnNativeWidgetVisibilityChanged(false); } -void DesktopWindowTreeHostX11::ToggleFullScreen() { - NOTIMPLEMENTED(); -} - gfx::Rect DesktopWindowTreeHostX11::GetBounds() const { return bounds_; } @@ -809,13 +805,6 @@ void DesktopWindowTreeHostX11::SetBounds(const gfx::Rect& bounds) { compositor()->ScheduleRedrawRect(gfx::Rect(bounds.size())); } -gfx::Insets DesktopWindowTreeHostX11::GetInsets() const { - return gfx::Insets(); -} - -void DesktopWindowTreeHostX11::SetInsets(const gfx::Insets& insets) { -} - gfx::Point DesktopWindowTreeHostX11::GetLocationOnNativeScreen() const { return bounds_.origin(); } @@ -867,15 +856,6 @@ bool DesktopWindowTreeHostX11::QueryMouseLocation( win_y_return >= 0 && win_y_return < bounds_.height()); } -bool DesktopWindowTreeHostX11::ConfineCursorToRootWindow() { - NOTIMPLEMENTED(); - return false; -} - -void DesktopWindowTreeHostX11::UnConfineCursor() { - NOTIMPLEMENTED(); -} - void DesktopWindowTreeHostX11::SetCursorNative(gfx::NativeCursor cursor) { XDefineCursor(xdisplay_, xwindow_, cursor.platform()); } diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h index bc20464..f08d207 100644 --- a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h +++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h @@ -133,17 +133,12 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; - virtual void ToggleFullScreen() OVERRIDE; virtual gfx::Rect GetBounds() const OVERRIDE; virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; - virtual gfx::Insets GetInsets() const OVERRIDE; - virtual void SetInsets(const gfx::Insets& insets) OVERRIDE; virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; virtual void SetCapture() OVERRIDE; virtual void ReleaseCapture() OVERRIDE; virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE; - virtual bool ConfineCursorToRootWindow() OVERRIDE; - virtual void UnConfineCursor() OVERRIDE; virtual void PostNativeEvent(const base::NativeEvent& native_event) OVERRIDE; virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; virtual void SetCursorNative(gfx::NativeCursor cursor) OVERRIDE; |