OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/widget/desktop_native_widget_helper_aura.h" | 5 #include "ui/views/widget/desktop_native_widget_helper_aura.h" |
6 | 6 |
7 #include "ui/aura/root_window.h" | 7 #include "ui/aura/root_window.h" |
8 #include "ui/aura/desktop/desktop_activation_client.h" | 8 #include "ui/aura/desktop/desktop_activation_client.h" |
9 #include "ui/aura/desktop/desktop_dispatcher_client.h" | 9 #include "ui/aura/desktop/desktop_dispatcher_client.h" |
10 #include "ui/aura/client/dispatcher_client.h" | 10 #include "ui/aura/client/dispatcher_client.h" |
| 11 #include "ui/aura/client/screen_position_client.h" |
11 #include "ui/aura/shared/input_method_event_filter.h" | 12 #include "ui/aura/shared/input_method_event_filter.h" |
12 #include "ui/aura/shared/root_window_event_filter.h" | 13 #include "ui/aura/shared/root_window_event_filter.h" |
13 #include "ui/views/widget/native_widget_aura.h" | 14 #include "ui/views/widget/native_widget_aura.h" |
14 | 15 |
15 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
16 #include "ui/base/win/hwnd_subclass.h" | 17 #include "ui/base/win/hwnd_subclass.h" |
17 #include "ui/views/widget/widget_message_filter.h" | 18 #include "ui/views/widget/widget_message_filter.h" |
18 #elif defined(USE_X11) | 19 #elif defined(USE_X11) |
19 #include "ui/views/widget/x11_window_event_filter.h" | 20 #include "ui/views/widget/x11_window_event_filter.h" |
20 #endif | 21 #endif |
21 | 22 |
22 namespace views { | 23 namespace views { |
23 | 24 |
| 25 namespace { |
| 26 |
| 27 // Client that always offsets the passed in point by the RootHost's origin. |
| 28 class RootWindowScreenPositionClient |
| 29 : public aura::client::ScreenPositionClient { |
| 30 public: |
| 31 explicit RootWindowScreenPositionClient(aura::RootWindow* root_window) |
| 32 : root_window_(root_window) {} |
| 33 virtual ~RootWindowScreenPositionClient() {} |
| 34 |
| 35 // aura::client::ScreenPositionClient: |
| 36 virtual void ConvertToScreenPoint(gfx::Point* screen_point) OVERRIDE { |
| 37 gfx::Point origin = root_window_->GetHostOrigin(); |
| 38 screen_point->Offset(origin.x(), origin.y()); |
| 39 } |
| 40 |
| 41 private: |
| 42 aura::RootWindow* root_window_; |
| 43 }; |
| 44 |
| 45 // Client that always offsets by the toplevel RootWindow of the passed in child |
| 46 // NativeWidgetAura. |
| 47 class EmbeddedWindowScreenPositionClient |
| 48 : public aura::client::ScreenPositionClient { |
| 49 public: |
| 50 explicit EmbeddedWindowScreenPositionClient(NativeWidgetAura* widget) |
| 51 : widget_(widget) {} |
| 52 virtual ~EmbeddedWindowScreenPositionClient() {} |
| 53 |
| 54 // aura::client::ScreenPositionClient: |
| 55 virtual void ConvertToScreenPoint(gfx::Point* screen_point) OVERRIDE { |
| 56 aura::RootWindow* root = |
| 57 widget_->GetNativeWindow()->GetRootWindow()->GetRootWindow(); |
| 58 gfx::Point origin = root->GetHostOrigin(); |
| 59 screen_point->Offset(origin.x(), origin.y()); |
| 60 } |
| 61 |
| 62 private: |
| 63 NativeWidgetAura* widget_; |
| 64 }; |
| 65 |
| 66 } // namespace |
| 67 |
24 DesktopNativeWidgetHelperAura::DesktopNativeWidgetHelperAura( | 68 DesktopNativeWidgetHelperAura::DesktopNativeWidgetHelperAura( |
25 NativeWidgetAura* widget) | 69 NativeWidgetAura* widget) |
26 : widget_(widget), | 70 : widget_(widget), |
27 root_window_event_filter_(NULL), | 71 root_window_event_filter_(NULL), |
28 is_embedded_window_(false) { | 72 is_embedded_window_(false) { |
29 } | 73 } |
30 | 74 |
31 DesktopNativeWidgetHelperAura::~DesktopNativeWidgetHelperAura() { | 75 DesktopNativeWidgetHelperAura::~DesktopNativeWidgetHelperAura() { |
32 if (root_window_event_filter_) { | 76 if (root_window_event_filter_) { |
33 #if defined(USE_X11) | 77 #if defined(USE_X11) |
34 root_window_event_filter_->RemoveFilter(x11_window_event_filter_.get()); | 78 root_window_event_filter_->RemoveFilter(x11_window_event_filter_.get()); |
35 #endif | 79 #endif |
36 | 80 |
37 root_window_event_filter_->RemoveFilter(input_method_filter_.get()); | 81 root_window_event_filter_->RemoveFilter(input_method_filter_.get()); |
38 } | 82 } |
39 } | 83 } |
40 | 84 |
41 void DesktopNativeWidgetHelperAura::PreInitialize( | 85 void DesktopNativeWidgetHelperAura::PreInitialize( |
| 86 aura::Window* window, |
42 const Widget::InitParams& params) { | 87 const Widget::InitParams& params) { |
43 #if !defined(OS_WIN) | 88 #if !defined(OS_WIN) |
44 // We don't want the status bubble or the omnibox to get their own root | 89 // We don't want the status bubble or the omnibox to get their own root |
45 // window on the desktop; on Linux | 90 // window on the desktop; on Linux |
46 // | 91 // |
47 // TODO(erg): This doesn't map perfectly to what I want to do. TYPE_POPUP is | 92 // TODO(erg): This doesn't map perfectly to what I want to do. TYPE_POPUP is |
48 // used for lots of stuff, like dragged tabs, and I only want this to trigger | 93 // used for lots of stuff, like dragged tabs, and I only want this to trigger |
49 // for the status bubble and the omnibox. | 94 // for the status bubble and the omnibox. |
50 if (params.type == Widget::InitParams::TYPE_POPUP) { | 95 if (params.type == Widget::InitParams::TYPE_POPUP) { |
51 is_embedded_window_ = true; | 96 is_embedded_window_ = true; |
| 97 position_client_.reset(new EmbeddedWindowScreenPositionClient(widget_)); |
| 98 aura::client::SetScreenPositionClient(window, position_client_.get()); |
52 return; | 99 return; |
53 } else if (params.type == Widget::InitParams::TYPE_CONTROL) { | 100 } else if (params.type == Widget::InitParams::TYPE_CONTROL) { |
54 return; | 101 return; |
55 } | 102 } |
56 #endif | 103 #endif |
57 | 104 |
58 gfx::Rect bounds = params.bounds; | 105 gfx::Rect bounds = params.bounds; |
59 if (bounds.IsEmpty()) { | 106 if (bounds.IsEmpty()) { |
60 // We must pass some non-zero value when we initialize a RootWindow. This | 107 // We must pass some non-zero value when we initialize a RootWindow. This |
61 // will probably be SetBounds()ed soon. | 108 // will probably be SetBounds()ed soon. |
(...skipping 16 matching lines...) Expand all Loading... |
78 root_window_event_filter_->AddFilter(x11_window_event_filter_.get()); | 125 root_window_event_filter_->AddFilter(x11_window_event_filter_.get()); |
79 #endif | 126 #endif |
80 | 127 |
81 root_window_->AddRootWindowObserver(this); | 128 root_window_->AddRootWindowObserver(this); |
82 | 129 |
83 aura::client::SetActivationClient( | 130 aura::client::SetActivationClient( |
84 root_window_.get(), | 131 root_window_.get(), |
85 new aura::DesktopActivationClient(root_window_.get())); | 132 new aura::DesktopActivationClient(root_window_.get())); |
86 aura::client::SetDispatcherClient(root_window_.get(), | 133 aura::client::SetDispatcherClient(root_window_.get(), |
87 new aura::DesktopDispatcherClient); | 134 new aura::DesktopDispatcherClient); |
| 135 |
| 136 position_client_.reset( |
| 137 new RootWindowScreenPositionClient(root_window_.get())); |
| 138 aura::client::SetScreenPositionClient(window, position_client_.get()); |
88 } | 139 } |
89 | 140 |
90 void DesktopNativeWidgetHelperAura::PostInitialize() { | 141 void DesktopNativeWidgetHelperAura::PostInitialize() { |
91 #if defined(OS_WIN) | 142 #if defined(OS_WIN) |
92 subclass_.reset(new ui::HWNDSubclass(root_window_->GetAcceleratedWidget())); | 143 subclass_.reset(new ui::HWNDSubclass(root_window_->GetAcceleratedWidget())); |
93 subclass_->SetFilter(new WidgetMessageFilter(root_window_.get(), | 144 subclass_->SetFilter(new WidgetMessageFilter(root_window_.get(), |
94 widget_->GetWidget())); | 145 widget_->GetWidget())); |
95 #endif | 146 #endif |
96 } | 147 } |
97 | 148 |
(...skipping 20 matching lines...) Expand all Loading... |
118 aura::RootWindow* root = | 169 aura::RootWindow* root = |
119 widget_->GetNativeWindow()->GetRootWindow()->GetRootWindow(); | 170 widget_->GetNativeWindow()->GetRootWindow()->GetRootWindow(); |
120 gfx::Point point = root->GetHostOrigin(); | 171 gfx::Point point = root->GetHostOrigin(); |
121 out_bounds.set_x(out_bounds.x() - point.x()); | 172 out_bounds.set_x(out_bounds.x() - point.x()); |
122 out_bounds.set_y(out_bounds.y() - point.y()); | 173 out_bounds.set_y(out_bounds.y() - point.y()); |
123 } | 174 } |
124 | 175 |
125 return out_bounds; | 176 return out_bounds; |
126 } | 177 } |
127 | 178 |
128 gfx::Rect DesktopNativeWidgetHelperAura::ChangeRootWindowBoundsToScreenBounds( | |
129 const gfx::Rect& bounds) { | |
130 gfx::Rect out_bounds = bounds; | |
131 if (root_window_.get()) { | |
132 out_bounds.Offset(root_window_->GetHostOrigin()); | |
133 } else if (is_embedded_window_) { | |
134 aura::RootWindow* root = | |
135 widget_->GetNativeWindow()->GetRootWindow()->GetRootWindow(); | |
136 out_bounds.Offset(root->GetHostOrigin()); | |
137 } | |
138 return out_bounds; | |
139 } | |
140 | |
141 //////////////////////////////////////////////////////////////////////////////// | 179 //////////////////////////////////////////////////////////////////////////////// |
142 // DesktopNativeWidgetHelperAura, aura::RootWindowObserver implementation: | 180 // DesktopNativeWidgetHelperAura, aura::RootWindowObserver implementation: |
143 | 181 |
144 void DesktopNativeWidgetHelperAura::OnRootWindowResized( | 182 void DesktopNativeWidgetHelperAura::OnRootWindowResized( |
145 const aura::RootWindow* root, | 183 const aura::RootWindow* root, |
146 const gfx::Size& old_size) { | 184 const gfx::Size& old_size) { |
147 DCHECK_EQ(root, root_window_.get()); | 185 DCHECK_EQ(root, root_window_.get()); |
148 widget_->SetBounds(gfx::Rect(root->GetHostOrigin(), | 186 widget_->SetBounds(gfx::Rect(root->GetHostOrigin(), |
149 root->GetHostSize())); | 187 root->GetHostSize())); |
150 } | 188 } |
151 | 189 |
152 void DesktopNativeWidgetHelperAura::OnRootWindowHostClosed( | 190 void DesktopNativeWidgetHelperAura::OnRootWindowHostClosed( |
153 const aura::RootWindow* root) { | 191 const aura::RootWindow* root) { |
154 DCHECK_EQ(root, root_window_.get()); | 192 DCHECK_EQ(root, root_window_.get()); |
155 widget_->GetWidget()->Close(); | 193 widget_->GetWidget()->Close(); |
156 } | 194 } |
157 | 195 |
158 } // namespace views | 196 } // namespace views |
OLD | NEW |