Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/host/ash_window_tree_host.h" | 5 #include "ash/host/ash_window_tree_host.h" |
| 6 | 6 |
| 7 #include "ash/host/ash_window_tree_host_init_params.h" | 7 #include "ash/host/ash_window_tree_host_init_params.h" |
| 8 #include "ash/host/root_window_transformer.h" | 8 #include "ash/host/root_window_transformer.h" |
| 9 #include "ash/host/transformer_helper.h" | 9 #include "ash/host/transformer_helper.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "ui/aura/client/screen_position_client.h" | |
| 11 #include "ui/aura/window_tree_host_ozone.h" | 12 #include "ui/aura/window_tree_host_ozone.h" |
| 12 #include "ui/gfx/geometry/insets.h" | 13 #include "ui/gfx/geometry/insets.h" |
| 13 #include "ui/gfx/transform.h" | 14 #include "ui/gfx/transform.h" |
| 14 | 15 |
| 15 namespace ash { | 16 namespace ash { |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 class AshWindowTreeHostOzone : public AshWindowTreeHost, | 19 class AshWindowTreeHostOzone : public AshWindowTreeHost, |
| 19 public aura::WindowTreeHostOzone { | 20 public aura::WindowTreeHostOzone { |
| 20 public: | 21 public: |
| 21 explicit AshWindowTreeHostOzone(const gfx::Rect& initial_bounds); | 22 explicit AshWindowTreeHostOzone(const gfx::Rect& initial_bounds); |
| 22 virtual ~AshWindowTreeHostOzone(); | 23 virtual ~AshWindowTreeHostOzone(); |
| 23 | 24 |
| 24 private: | 25 private: |
| 26 void TranslateMouseEvent(ui::LocatedEvent* event); | |
| 27 | |
| 25 // AshWindowTreeHost: | 28 // AshWindowTreeHost: |
| 26 virtual void ToggleFullScreen() override; | 29 virtual void ToggleFullScreen() override; |
| 27 virtual bool ConfineCursorToRootWindow() override; | 30 virtual bool ConfineCursorToRootWindow() override; |
| 28 virtual void UnConfineCursor() override; | 31 virtual void UnConfineCursor() override; |
| 29 virtual void SetRootWindowTransformer( | 32 virtual void SetRootWindowTransformer( |
| 30 scoped_ptr<RootWindowTransformer> transformer) override; | 33 scoped_ptr<RootWindowTransformer> transformer) override; |
| 31 virtual gfx::Insets GetHostInsets() const override; | 34 virtual gfx::Insets GetHostInsets() const override; |
| 32 virtual aura::WindowTreeHost* AsWindowTreeHost() override; | 35 virtual aura::WindowTreeHost* AsWindowTreeHost() override; |
| 33 virtual void SetRootTransform(const gfx::Transform& transform) override; | 36 virtual void SetRootTransform(const gfx::Transform& transform) override; |
| 34 virtual gfx::Transform GetRootTransform() const override; | 37 virtual gfx::Transform GetRootTransform() const override; |
| 35 virtual gfx::Transform GetInverseRootTransform() const override; | 38 virtual gfx::Transform GetInverseRootTransform() const override; |
| 36 virtual void UpdateRootWindowSize(const gfx::Size& host_size) override; | 39 virtual void UpdateRootWindowSize(const gfx::Size& host_size) override; |
| 40 virtual void DispatchEvent(ui::Event* event) override; | |
| 37 | 41 |
| 38 TransformerHelper transformer_helper_; | 42 TransformerHelper transformer_helper_; |
| 39 | 43 |
| 40 DISALLOW_COPY_AND_ASSIGN(AshWindowTreeHostOzone); | 44 DISALLOW_COPY_AND_ASSIGN(AshWindowTreeHostOzone); |
| 41 }; | 45 }; |
| 42 | 46 |
| 43 AshWindowTreeHostOzone::AshWindowTreeHostOzone(const gfx::Rect& initial_bounds) | 47 AshWindowTreeHostOzone::AshWindowTreeHostOzone(const gfx::Rect& initial_bounds) |
| 44 : aura::WindowTreeHostOzone(initial_bounds), | 48 : aura::WindowTreeHostOzone(initial_bounds), |
| 45 transformer_helper_(this) {} | 49 transformer_helper_(this) {} |
| 46 | 50 |
| 47 AshWindowTreeHostOzone::~AshWindowTreeHostOzone() {} | 51 AshWindowTreeHostOzone::~AshWindowTreeHostOzone() {} |
| 48 | 52 |
| 53 void AshWindowTreeHostOzone::TranslateMouseEvent(ui::LocatedEvent* event) { | |
| 54 aura::Window* root_window = window(); | |
| 55 aura::client::ScreenPositionClient* screen_position_client = | |
| 56 aura::client::GetScreenPositionClient(root_window); | |
| 57 gfx::Rect local(GetBounds().size()); | |
| 58 | |
| 59 local.Inset(transformer_helper_.GetHostInsets()); | |
| 60 | |
| 61 if (screen_position_client && !local.Contains(event->location())) { | |
| 62 gfx::Point location(event->location()); | |
| 63 // In order to get the correct point in screen coordinates during | |
| 64 // passive grab, we first need to find on which host window the | |
| 65 // mouse is on, and find out the screen coordinates on that host | |
| 66 // window, then convert it back to this host window's coordinate. | |
| 67 screen_position_client->ConvertHostPointToScreen(root_window, &location); | |
| 68 screen_position_client->ConvertPointFromScreen(root_window, &location); | |
| 69 ConvertPointToHost(&location); | |
| 70 event->set_location(location); | |
| 71 event->set_root_location(location); | |
| 72 } | |
|
sadrul
2014/11/24 22:27:04
You should refactor this so you are not duplicatin
| |
| 73 } | |
| 74 | |
| 49 void AshWindowTreeHostOzone::ToggleFullScreen() { | 75 void AshWindowTreeHostOzone::ToggleFullScreen() { |
| 50 NOTIMPLEMENTED(); | 76 NOTIMPLEMENTED(); |
| 51 } | 77 } |
| 52 | 78 |
| 53 bool AshWindowTreeHostOzone::ConfineCursorToRootWindow() { | 79 bool AshWindowTreeHostOzone::ConfineCursorToRootWindow() { |
| 54 return false; | 80 return false; |
| 55 } | 81 } |
| 56 | 82 |
| 57 void AshWindowTreeHostOzone::UnConfineCursor() { | 83 void AshWindowTreeHostOzone::UnConfineCursor() { |
| 58 NOTIMPLEMENTED(); | 84 NOTIMPLEMENTED(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 80 } | 106 } |
| 81 | 107 |
| 82 gfx::Transform AshWindowTreeHostOzone::GetInverseRootTransform() const { | 108 gfx::Transform AshWindowTreeHostOzone::GetInverseRootTransform() const { |
| 83 return transformer_helper_.GetInverseTransform(); | 109 return transformer_helper_.GetInverseTransform(); |
| 84 } | 110 } |
| 85 | 111 |
| 86 void AshWindowTreeHostOzone::UpdateRootWindowSize(const gfx::Size& host_size) { | 112 void AshWindowTreeHostOzone::UpdateRootWindowSize(const gfx::Size& host_size) { |
| 87 transformer_helper_.UpdateWindowSize(host_size); | 113 transformer_helper_.UpdateWindowSize(host_size); |
| 88 } | 114 } |
| 89 | 115 |
| 116 void AshWindowTreeHostOzone::DispatchEvent(ui::Event* event) { | |
| 117 if (event->IsMouseEvent() || event->IsScrollEvent()) | |
| 118 TranslateMouseEvent(static_cast<ui::LocatedEvent*>(event)); | |
|
sadrul
2014/11/24 22:27:04
We do this translation for touch-events too on x11
| |
| 119 SendEventToProcessor(event); | |
| 120 } | |
| 121 | |
| 90 } // namespace | 122 } // namespace |
| 91 | 123 |
| 92 AshWindowTreeHost* AshWindowTreeHost::Create( | 124 AshWindowTreeHost* AshWindowTreeHost::Create( |
| 93 const AshWindowTreeHostInitParams& init_params) { | 125 const AshWindowTreeHostInitParams& init_params) { |
| 94 return new AshWindowTreeHostOzone(init_params.initial_bounds); | 126 return new AshWindowTreeHostOzone(init_params.initial_bounds); |
| 95 } | 127 } |
| 96 | 128 |
| 97 } // namespace ash | 129 } // namespace ash |
| OLD | NEW |