Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: ui/views/widget/android/native_widget_android.cc

Issue 1403293003: Introduce AndroidFocusRules and NativeWidgetAndroid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/widget/android/native_widget_android.h ('k') | ui/views/widget/native_widget_aura.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/native_widget_aura.h" 5 #include "ui/views/widget/android/native_widget_android.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/run_loop.h"
8 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
9 #include "third_party/skia/include/core/SkRegion.h" 10 #include "third_party/skia/include/core/SkRegion.h"
10 #include "ui/aura/client/aura_constants.h" 11 #include "ui/aura/client/aura_constants.h"
11 #include "ui/aura/client/cursor_client.h" 12 #include "ui/aura/client/cursor_client.h"
13 #include "ui/aura/client/default_capture_client.h"
12 #include "ui/aura/client/focus_client.h" 14 #include "ui/aura/client/focus_client.h"
13 #include "ui/aura/client/screen_position_client.h" 15 #include "ui/aura/client/screen_position_client.h"
14 #include "ui/aura/client/window_tree_client.h" 16 #include "ui/aura/client/window_tree_client.h"
15 #include "ui/aura/env.h" 17 #include "ui/aura/env.h"
16 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
17 #include "ui/aura/window_event_dispatcher.h" 19 #include "ui/aura/window_event_dispatcher.h"
18 #include "ui/aura/window_observer.h" 20 #include "ui/aura/window_observer.h"
19 #include "ui/aura/window_tree_host.h" 21 #include "ui/aura/window_tree_host.h"
20 #include "ui/base/dragdrop/os_exchange_data.h" 22 #include "ui/base/dragdrop/os_exchange_data.h"
21 #include "ui/base/ui_base_types.h" 23 #include "ui/base/ui_base_types.h"
22 #include "ui/compositor/layer.h" 24 #include "ui/compositor/layer.h"
23 #include "ui/events/event.h" 25 #include "ui/events/event.h"
24 #include "ui/gfx/canvas.h" 26 #include "ui/gfx/canvas.h"
25 #include "ui/gfx/font_list.h" 27 #include "ui/gfx/font_list.h"
26 #include "ui/gfx/screen.h" 28 #include "ui/gfx/screen.h"
27 #include "ui/native_theme/native_theme_aura.h" 29 #include "ui/native_theme/native_theme_aura.h"
28 #include "ui/views/drag_utils.h" 30 #include "ui/views/drag_utils.h"
29 #include "ui/views/views_delegate.h" 31 #include "ui/views/views_delegate.h"
32 #include "ui/views/widget/android/android_focus_rules.h"
30 #include "ui/views/widget/drop_helper.h" 33 #include "ui/views/widget/drop_helper.h"
34 #include "ui/views/widget/native_widget_aura.h"
31 #include "ui/views/widget/native_widget_delegate.h" 35 #include "ui/views/widget/native_widget_delegate.h"
32 #include "ui/views/widget/root_view.h" 36 #include "ui/views/widget/root_view.h"
33 #include "ui/views/widget/tooltip_manager_aura.h" 37 #include "ui/views/widget/tooltip_manager_aura.h"
34 #include "ui/views/widget/widget_aura_utils.h" 38 #include "ui/views/widget/widget_aura_utils.h"
35 #include "ui/views/widget/widget_delegate.h" 39 #include "ui/views/widget/widget_delegate.h"
36 #include "ui/views/widget/window_reorderer.h" 40 #include "ui/views/widget/window_reorderer.h"
41 #include "ui/wm/core/default_activation_client.h"
42 #include "ui/wm/core/default_screen_position_client.h"
43 #include "ui/wm/core/focus_controller.h"
37 #include "ui/wm/core/shadow_types.h" 44 #include "ui/wm/core/shadow_types.h"
38 #include "ui/wm/core/window_animations.h" 45 #include "ui/wm/core/window_animations.h"
39 #include "ui/wm/core/window_util.h" 46 #include "ui/wm/core/window_util.h"
40 #include "ui/wm/public/activation_client.h" 47 #include "ui/wm/public/activation_client.h"
48 #include "ui/wm/public/dispatcher_client.h"
41 #include "ui/wm/public/drag_drop_client.h" 49 #include "ui/wm/public/drag_drop_client.h"
42 #include "ui/wm/public/window_move_client.h" 50 #include "ui/wm/public/window_move_client.h"
43 #include "ui/wm/public/window_types.h" 51 #include "ui/wm/public/window_types.h"
44 52
45 #if defined(OS_WIN) 53 // TODO(bshe): Most of the code is copied from NativeWidgetAura. There will be
46 #include "base/win/scoped_gdi_object.h" 54 // more differences overtime. For upstreaming purpose, keep the change minimal.
47 #include "base/win/win_util.h"
48 #include "ui/base/l10n/l10n_util_win.h"
49 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
50 #endif
51
52 #if defined(USE_X11) && !defined(OS_CHROMEOS)
53 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
54 #endif
55
56 #if !defined(OS_CHROMEOS)
57 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
58 #include "ui/views/widget/desktop_aura/desktop_window_tree_host.h"
59 #endif
60
61 namespace views {
62 55
63 namespace { 56 namespace {
64 57
65 void SetRestoreBounds(aura::Window* window, const gfx::Rect& bounds) { 58 void SetRestoreBounds(aura::Window* window, const gfx::Rect& bounds) {
66 window->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds)); 59 window->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds));
67 } 60 }
68 61
62 class NativeWidgetAndroidWindowTreeClient
63 : public aura::client::WindowTreeClient {
64 public:
65 explicit NativeWidgetAndroidWindowTreeClient(aura::Window* root_window)
66 : root_window_(root_window) {
67 aura::client::SetWindowTreeClient(root_window_, this);
68 }
69 ~NativeWidgetAndroidWindowTreeClient() override {
70 aura::client::SetWindowTreeClient(root_window_, NULL);
71 }
72
73 // Overridden from client::WindowTreeClient:
74 aura::Window* GetDefaultParent(aura::Window* context,
75 aura::Window* window,
76 const gfx::Rect& bounds) override {
77 return root_window_;
78 }
79
80 private:
81 aura::Window* root_window_;
82
83 DISALLOW_COPY_AND_ASSIGN(NativeWidgetAndroidWindowTreeClient);
84 };
85
86 class AndroidDispatcherClient : public aura::client::DispatcherClient {
mfomitchev 2015/11/06 16:45:50 We are trying to get rid of nested msg loops, so h
bshe 2015/11/11 00:38:30 Done.
87 public:
88 AndroidDispatcherClient() : dispatcher_(nullptr) {}
89 ~AndroidDispatcherClient() override {}
90
91 base::MessagePumpDispatcher* dispatcher() { return dispatcher_; }
92
93 // aura::client::DispatcherClient:
94 void PrepareNestedLoopClosures(base::MessagePumpDispatcher* dispatcher,
95 base::Closure* run_closure,
96 base::Closure* quit_closure) override {
97 scoped_ptr<base::RunLoop> run_loop(new base::RunLoop());
98 *quit_closure = run_loop->QuitClosure();
99 *run_closure =
100 base::Bind(&AndroidDispatcherClient::RunNestedDispatcher,
101 base::Unretained(this), base::Passed(&run_loop), dispatcher);
102 }
103
104 private:
105 void RunNestedDispatcher(scoped_ptr<base::RunLoop> run_loop,
106 base::MessagePumpDispatcher* dispatcher) {
107 base::AutoReset<base::MessagePumpDispatcher*> reset_dispatcher(&dispatcher_,
108 dispatcher);
109 base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
110 base::MessageLoop::ScopedNestableTaskAllower allow(loop);
111 run_loop->Run();
112 }
113
114 base::MessagePumpDispatcher* dispatcher_;
115
116 DISALLOW_COPY_AND_ASSIGN(AndroidDispatcherClient);
117 };
118
69 } // namespace 119 } // namespace
70 120
121 namespace views {
122
71 //////////////////////////////////////////////////////////////////////////////// 123 ////////////////////////////////////////////////////////////////////////////////
72 // NativeWidgetAura, public: 124 // NativeWidgetAndroid, public
73 125
74 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) 126 NativeWidgetAndroid::NativeWidgetAndroid(
127 internal::NativeWidgetDelegate* delegate)
75 : delegate_(delegate), 128 : delegate_(delegate),
76 window_(new aura::Window(this)), 129 window_(new aura::Window(this)),
77 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), 130 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
78 destroying_(false), 131 destroying_(false),
79 cursor_(gfx::kNullCursor), 132 cursor_(gfx::kNullCursor),
80 saved_window_state_(ui::SHOW_STATE_DEFAULT), 133 saved_window_state_(ui::SHOW_STATE_DEFAULT),
81 close_widget_factory_(this) { 134 close_widget_factory_(this) {
82 aura::client::SetFocusChangeObserver(window_, this); 135 aura::client::SetFocusChangeObserver(window_, this);
83 aura::client::SetActivationChangeObserver(window_, this); 136 aura::client::SetActivationChangeObserver(window_, this);
84 } 137 }
85 138
86 // static 139 ////////////////////////////////////////////////////////////////////////////////
87 void NativeWidgetAura::RegisterNativeWidgetForWindow( 140 // NativeWidgetAndroid, NativeWidgetAndroid implementation:
88 internal::NativeWidgetPrivate* native_widget,
89 aura::Window* window) {
90 window->set_user_data(native_widget);
91 }
92 141
93 //////////////////////////////////////////////////////////////////////////////// 142 void NativeWidgetAndroid::InitNativeWidget(const Widget::InitParams& params) {
94 // NativeWidgetAura, internal::NativeWidgetPrivate implementation: 143 // TODO(bshe): Get rid of the hard coded size. Tracked in crbug.com/551923.
144 host_.reset(aura::WindowTreeHost::Create(gfx::Rect(0, 0, 800, 600)));
145 host_->InitHost();
146 host_->Show();
95 147
96 void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { 148 window_tree_client_.reset(
149 new NativeWidgetAndroidWindowTreeClient(host_->window()));
150
151 focus_client_.reset(new wm::FocusController(new AndroidFocusRules));
152 aura::client::SetFocusClient(host_->window(), focus_client_.get());
153 host_->window()->AddPreTargetHandler(focus_client_.get());
154
155 new wm::DefaultActivationClient(host_->window());
156
157 capture_client_.reset(
158 new aura::client::DefaultCaptureClient(host_->window()));
159
160 screen_position_client_.reset(new wm::DefaultScreenPositionClient);
161 aura::client::SetScreenPositionClient(host_->window(),
162 screen_position_client_.get());
163 dispatcher_client_.reset(new AndroidDispatcherClient);
164 aura::client::SetDispatcherClient(host_->window(), dispatcher_client_.get());
165
97 // Aura needs to know which desktop (Ash or regular) will manage this widget. 166 // Aura needs to know which desktop (Ash or regular) will manage this widget.
98 // See Widget::InitParams::context for details. 167 // See Widget::InitParams::context for details.
99 DCHECK(params.parent || params.context); 168 DCHECK(params.parent || params.context);
mfomitchev 2015/11/06 16:45:50 This seems wrong? This is top-level...
bshe 2015/11/11 00:38:30 removed.
100 169
101 ownership_ = params.ownership; 170 ownership_ = params.ownership;
102 171
103 RegisterNativeWidgetForWindow(this, window_); 172 NativeWidgetAura::RegisterNativeWidgetForWindow(this, window_);
104 window_->SetType(GetAuraWindowTypeForWidgetType(params.type)); 173 window_->SetType(GetAuraWindowTypeForWidgetType(params.type));
105 window_->SetProperty(aura::client::kShowStateKey, params.show_state); 174 window_->SetProperty(aura::client::kShowStateKey, params.show_state);
106 if (params.type == Widget::InitParams::TYPE_BUBBLE) 175 if (params.type == Widget::InitParams::TYPE_BUBBLE)
107 aura::client::SetHideOnDeactivate(window_, true); 176 aura::client::SetHideOnDeactivate(window_, true);
108 window_->SetTransparent( 177 window_->SetTransparent(params.opacity ==
109 params.opacity == Widget::InitParams::TRANSLUCENT_WINDOW); 178 Widget::InitParams::TRANSLUCENT_WINDOW);
110 window_->Init(params.layer_type); 179 window_->Init(params.layer_type);
111 if (params.shadow_type == Widget::InitParams::SHADOW_TYPE_NONE) 180 if (params.shadow_type == Widget::InitParams::SHADOW_TYPE_NONE)
112 SetShadowType(window_, wm::SHADOW_TYPE_NONE); 181 SetShadowType(window_, wm::SHADOW_TYPE_NONE);
113 else if (params.shadow_type == Widget::InitParams::SHADOW_TYPE_DROP) 182 else if (params.shadow_type == Widget::InitParams::SHADOW_TYPE_DROP)
114 SetShadowType(window_, wm::SHADOW_TYPE_RECTANGULAR); 183 SetShadowType(window_, wm::SHADOW_TYPE_RECTANGULAR);
115 if (params.type == Widget::InitParams::TYPE_CONTROL) 184 if (params.type == Widget::InitParams::TYPE_CONTROL)
116 window_->Show(); 185 window_->Show();
117 186
118 delegate_->OnNativeWidgetCreated(false); 187 delegate_->OnNativeWidgetCreated(false);
119 188
120 gfx::Rect window_bounds = params.bounds; 189 gfx::Rect window_bounds = params.bounds;
121 gfx::NativeView parent = params.parent; 190 gfx::NativeView parent = params.parent;
mfomitchev 2015/11/06 16:45:50 Not sure if this code is appropriate for top-level
bshe 2015/11/11 00:38:30 Right. Anything related to parent is probably not
122 gfx::NativeView context = params.context; 191 gfx::NativeView context = params.context;
123 if (!params.child) { 192 if (!params.child) {
124 // Set up the transient child before the window is added. This way the 193 // Set up the transient child before the window is added. This way the
125 // LayoutManager knows the window has a transient parent. 194 // LayoutManager knows the window has a transient parent.
126 if (parent && parent->type() != ui::wm::WINDOW_TYPE_UNKNOWN) { 195 if (parent && parent->type() != ui::wm::WINDOW_TYPE_UNKNOWN) {
127 wm::AddTransientChild(parent, window_); 196 wm::AddTransientChild(parent, window_);
128 if (!context) 197 if (!context)
129 context = parent; 198 context = parent;
130 parent = NULL; 199 parent = NULL;
131 } 200 }
132 // SetAlwaysOnTop before SetParent so that always-on-top container is used. 201 // SetAlwaysOnTop before SetParent so that always-on-top container is used.
133 SetAlwaysOnTop(params.keep_on_top); 202 SetAlwaysOnTop(params.keep_on_top);
134 // Make sure we have a real |window_bounds|. 203 // Make sure we have a real |window_bounds|.
135 if (parent && window_bounds == gfx::Rect()) { 204 if (parent && window_bounds == gfx::Rect()) {
136 // If a parent is specified but no bounds are given, 205 // If a parent is specified but no bounds are given,
137 // use the origin of the parent's display so that the widget 206 // use the origin of the parent's display so that the widget
138 // will be added to the same display as the parent. 207 // will be added to the same display as the parent.
139 gfx::Rect bounds = gfx::Screen::GetScreenFor(parent)-> 208 gfx::Rect bounds = gfx::Screen::GetScreenFor(parent)
140 GetDisplayNearestWindow(parent).bounds(); 209 ->GetDisplayNearestWindow(parent)
210 .bounds();
141 window_bounds.set_origin(bounds.origin()); 211 window_bounds.set_origin(bounds.origin());
142 } 212 }
143 } 213 }
144 214
145 // Set properties before adding to the parent so that its layout manager sees 215 // Set properties before adding to the parent so that its layout manager sees
146 // the correct values. 216 // the correct values.
147 OnSizeConstraintsChanged(); 217 OnSizeConstraintsChanged();
148 218
149 if (parent) { 219 if (parent) {
150 parent->AddChild(window_); 220 parent->AddChild(window_);
151 } else { 221 } else {
152 aura::client::ParentWindowWithContext( 222 aura::client::ParentWindowWithContext(window_, context->GetRootWindow(),
153 window_, context->GetRootWindow(), window_bounds); 223 window_bounds);
154 } 224 }
155 225
156 // Start observing property changes. 226 // Start observing property changes.
157 window_->AddObserver(this); 227 window_->AddObserver(this);
158 228
159 // Wait to set the bounds until we have a parent. That way we can know our 229 // Wait to set the bounds until we have a parent. That way we can know our
160 // true state/bounds (the LayoutManager may enforce a particular 230 // true state/bounds (the LayoutManager may enforce a particular
161 // state/bounds). 231 // state/bounds).
162 if (IsMaximized()) 232 if (IsMaximized())
163 SetRestoreBounds(window_, window_bounds); 233 SetRestoreBounds(window_, window_bounds);
164 else 234 else
165 SetBounds(window_bounds); 235 SetBounds(window_bounds);
166 window_->set_ignore_events(!params.accept_events); 236 window_->set_ignore_events(!params.accept_events);
167 DCHECK(GetWidget()->GetRootView()); 237 DCHECK(GetWidget()->GetRootView());
168 if (params.type != Widget::InitParams::TYPE_TOOLTIP) 238 if (params.type != Widget::InitParams::TYPE_TOOLTIP)
169 tooltip_manager_.reset(new views::TooltipManagerAura(GetWidget())); 239 tooltip_manager_.reset(new views::TooltipManagerAura(GetWidget()));
170 240
171 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView())); 241 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView()));
172 if (params.type != Widget::InitParams::TYPE_TOOLTIP && 242 if (params.type != Widget::InitParams::TYPE_TOOLTIP &&
173 params.type != Widget::InitParams::TYPE_POPUP) { 243 params.type != Widget::InitParams::TYPE_POPUP) {
174 aura::client::SetDragDropDelegate(window_, this); 244 aura::client::SetDragDropDelegate(window_, this);
175 } 245 }
176 246
177 aura::client::SetActivationDelegate(window_, this); 247 aura::client::SetActivationDelegate(window_, this);
178 248
179 window_reorderer_.reset(new WindowReorderer(window_, 249 window_reorderer_.reset(
180 GetWidget()->GetRootView())); 250 new WindowReorderer(window_, GetWidget()->GetRootView()));
181 } 251 }
182 252
183 NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() { 253 NonClientFrameView* NativeWidgetAndroid::CreateNonClientFrameView() {
184 return NULL; 254 return NULL;
mfomitchev 2015/11/06 16:45:50 previous impl was better IMHO
bshe 2015/11/11 00:38:30 Done.
185 } 255 }
186 256
187 bool NativeWidgetAura::ShouldUseNativeFrame() const { 257 bool NativeWidgetAndroid::ShouldUseNativeFrame() const {
188 // There is only one frame type for aura. 258 // There is only one frame type for aura.
mfomitchev 2015/11/06 16:45:50 ditto
bshe 2015/11/11 00:38:30 Done.
189 return false; 259 return false;
190 } 260 }
191 261
192 bool NativeWidgetAura::ShouldWindowContentsBeTransparent() const { 262 bool NativeWidgetAndroid::ShouldWindowContentsBeTransparent() const {
193 return false; 263 return false;
mfomitchev 2015/11/06 16:45:51 ditto
bshe 2015/11/11 00:38:30 Done.
194 } 264 }
195 265
196 void NativeWidgetAura::FrameTypeChanged() { 266 void NativeWidgetAndroid::FrameTypeChanged() {
197 // This is called when the Theme has changed; forward the event to the root 267 // This is called when the Theme has changed; forward the event to the root
198 // widget. 268 // widget.
199 GetWidget()->ThemeChanged(); 269 GetWidget()->ThemeChanged();
mfomitchev 2015/11/06 16:45:51 We don't have themes.. maybe just leave NOTIMPLEME
bshe 2015/11/11 00:38:30 Done.
200 GetWidget()->GetRootView()->SchedulePaint(); 270 GetWidget()->GetRootView()->SchedulePaint();
201 } 271 }
202 272
203 Widget* NativeWidgetAura::GetWidget() { 273 Widget* NativeWidgetAndroid::GetWidget() {
204 return delegate_->AsWidget(); 274 return delegate_->AsWidget();
205 } 275 }
206 276
207 const Widget* NativeWidgetAura::GetWidget() const { 277 const Widget* NativeWidgetAndroid::GetWidget() const {
208 return delegate_->AsWidget(); 278 return delegate_->AsWidget();
209 } 279 }
210 280
211 gfx::NativeView NativeWidgetAura::GetNativeView() const { 281 gfx::NativeView NativeWidgetAndroid::GetNativeView() const {
212 return window_; 282 return window_;
213 } 283 }
214 284
215 gfx::NativeWindow NativeWidgetAura::GetNativeWindow() const { 285 gfx::NativeWindow NativeWidgetAndroid::GetNativeWindow() const {
216 return window_; 286 return window_;
217 } 287 }
218 288
219 Widget* NativeWidgetAura::GetTopLevelWidget() { 289 Widget* NativeWidgetAndroid::GetTopLevelWidget() {
220 NativeWidgetPrivate* native_widget = GetTopLevelNativeWidget(GetNativeView()); 290 NativeWidgetPrivate* native_widget = GetTopLevelNativeWidget(GetNativeView());
mfomitchev 2015/11/06 16:45:51 We are the top-level widget... use DNWA's impl?
bshe 2015/11/11 00:38:30 Done.
221 return native_widget ? native_widget->GetWidget() : NULL; 291 return native_widget ? native_widget->GetWidget() : NULL;
222 } 292 }
223 293
224 const ui::Compositor* NativeWidgetAura::GetCompositor() const { 294 const ui::Compositor* NativeWidgetAndroid::GetCompositor() const {
225 return window_ ? window_->layer()->GetCompositor() : NULL; 295 return window_ ? window_->layer()->GetCompositor() : NULL;
mfomitchev 2015/11/06 16:45:51 Sadrul suggested host_->compositor()
bshe 2015/11/11 00:38:30 Done.
226 } 296 }
227 297
228 const ui::Layer* NativeWidgetAura::GetLayer() const { 298 const ui::Layer* NativeWidgetAndroid::GetLayer() const {
229 return window_ ? window_->layer() : NULL; 299 return window_ ? window_->layer() : NULL;
mfomitchev 2015/11/06 16:45:51 See Sadrul's comment
bshe 2015/11/11 00:38:29 Done.
230 } 300 }
231 301
232 void NativeWidgetAura::ReorderNativeViews() { 302 void NativeWidgetAndroid::ReorderNativeViews() {
233 window_reorderer_->ReorderChildWindows(); 303 window_reorderer_->ReorderChildWindows();
234 } 304 }
235 305
236 void NativeWidgetAura::ViewRemoved(View* view) { 306 void NativeWidgetAndroid::ViewRemoved(View* view) {
237 DCHECK(drop_helper_.get() != NULL); 307 DCHECK(drop_helper_.get() != NULL);
mfomitchev 2015/11/06 16:45:50 We don't support DND, so NOTIMPLEMENTED() makes se
bshe 2015/11/11 00:38:30 Done.
238 drop_helper_->ResetTargetViewIfEquals(view); 308 drop_helper_->ResetTargetViewIfEquals(view);
239 } 309 }
240 310
241 void NativeWidgetAura::SetNativeWindowProperty(const char* name, void* value) { 311 void NativeWidgetAndroid::SetNativeWindowProperty(const char* name,
312 void* value) {
242 if (window_) 313 if (window_)
243 window_->SetNativeWindowProperty(name, value); 314 window_->SetNativeWindowProperty(name, value);
244 } 315 }
245 316
246 void* NativeWidgetAura::GetNativeWindowProperty(const char* name) const { 317 void* NativeWidgetAndroid::GetNativeWindowProperty(const char* name) const {
247 return window_ ? window_->GetNativeWindowProperty(name) : NULL; 318 return window_ ? window_->GetNativeWindowProperty(name) : NULL;
248 } 319 }
249 320
250 TooltipManager* NativeWidgetAura::GetTooltipManager() const { 321 TooltipManager* NativeWidgetAndroid::GetTooltipManager() const {
251 return tooltip_manager_.get(); 322 return tooltip_manager_.get();
252 } 323 }
253 324
254 void NativeWidgetAura::SetCapture() { 325 void NativeWidgetAndroid::SetCapture() {
255 if (window_) 326 if (window_)
256 window_->SetCapture(); 327 window_->SetCapture();
257 } 328 }
258 329
259 void NativeWidgetAura::ReleaseCapture() { 330 void NativeWidgetAndroid::ReleaseCapture() {
260 if (window_) 331 if (window_)
261 window_->ReleaseCapture(); 332 window_->ReleaseCapture();
262 } 333 }
263 334
264 bool NativeWidgetAura::HasCapture() const { 335 bool NativeWidgetAndroid::HasCapture() const {
265 return window_ && window_->HasCapture(); 336 return window_ && window_->HasCapture();
266 } 337 }
267 338
268 ui::InputMethod* NativeWidgetAura::GetInputMethod() { 339 ui::InputMethod* NativeWidgetAndroid::GetInputMethod() {
269 if (!window_) 340 if (!window_)
270 return nullptr; 341 return nullptr;
271 aura::Window* root_window = window_->GetRootWindow(); 342 aura::Window* root_window = window_->GetRootWindow();
272 return root_window ? root_window->GetHost()->GetInputMethod() : nullptr; 343 return root_window ? root_window->GetHost()->GetInputMethod() : nullptr;
273 } 344 }
274 345
275 void NativeWidgetAura::CenterWindow(const gfx::Size& size) { 346 void NativeWidgetAndroid::CenterWindow(const gfx::Size& size) {
mfomitchev 2015/11/06 16:45:51 See my previous comment - not sure this makes sens
bshe 2015/11/11 00:38:30 Left a TODO and used NOTIMPLEMENTED for now.
276 if (!window_) 347 if (!window_)
277 return; 348 return;
278 349
279 gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow()); 350 gfx::Rect parent_bounds(window_->parent()->GetBoundsInRootWindow());
280 // When centering window, we take the intersection of the host and 351 // When centering window, we take the intersection of the host and
281 // the parent. We assume the root window represents the visible 352 // the parent. We assume the root window represents the visible
282 // rect of a single screen. 353 // rect of a single screen.
283 gfx::Rect work_area = gfx::Screen::GetScreenFor(window_)-> 354 gfx::Rect work_area = gfx::Screen::GetScreenFor(window_)
284 GetDisplayNearestWindow(window_).work_area(); 355 ->GetDisplayNearestWindow(window_)
356 .work_area();
285 357
286 aura::client::ScreenPositionClient* screen_position_client = 358 aura::client::ScreenPositionClient* screen_position_client =
287 aura::client::GetScreenPositionClient(window_->GetRootWindow()); 359 aura::client::GetScreenPositionClient(window_->GetRootWindow());
288 if (screen_position_client) { 360 if (screen_position_client) {
289 gfx::Point origin = work_area.origin(); 361 gfx::Point origin = work_area.origin();
290 screen_position_client->ConvertPointFromScreen(window_->GetRootWindow(), 362 screen_position_client->ConvertPointFromScreen(window_->GetRootWindow(),
291 &origin); 363 &origin);
292 work_area.set_origin(origin); 364 work_area.set_origin(origin);
293 } 365 }
294 366
295 parent_bounds.Intersect(work_area); 367 parent_bounds.Intersect(work_area);
296 368
297 // If |window_|'s transient parent's bounds are big enough to fit it, then we 369 // If |window_|'s transient parent's bounds are big enough to fit it, then we
298 // center it with respect to the transient parent. 370 // center it with respect to the transient parent.
299 if (wm::GetTransientParent(window_)) { 371 if (wm::GetTransientParent(window_)) {
300 gfx::Rect transient_parent_rect = 372 gfx::Rect transient_parent_rect =
301 wm::GetTransientParent(window_)->GetBoundsInRootWindow(); 373 wm::GetTransientParent(window_)->GetBoundsInRootWindow();
302 transient_parent_rect.Intersect(work_area); 374 transient_parent_rect.Intersect(work_area);
303 if (transient_parent_rect.height() >= size.height() && 375 if (transient_parent_rect.height() >= size.height() &&
304 transient_parent_rect.width() >= size.width()) 376 transient_parent_rect.width() >= size.width())
305 parent_bounds = transient_parent_rect; 377 parent_bounds = transient_parent_rect;
306 } 378 }
307 379
308 gfx::Rect window_bounds( 380 gfx::Rect window_bounds(
309 parent_bounds.x() + (parent_bounds.width() - size.width()) / 2, 381 parent_bounds.x() + (parent_bounds.width() - size.width()) / 2,
310 parent_bounds.y() + (parent_bounds.height() - size.height()) / 2, 382 parent_bounds.y() + (parent_bounds.height() - size.height()) / 2,
311 size.width(), 383 size.width(), size.height());
312 size.height());
313 // Don't size the window bigger than the parent, otherwise the user may not be 384 // Don't size the window bigger than the parent, otherwise the user may not be
314 // able to close or move it. 385 // able to close or move it.
315 window_bounds.AdjustToFit(parent_bounds); 386 window_bounds.AdjustToFit(parent_bounds);
316 387
317 // Convert the bounds back relative to the parent. 388 // Convert the bounds back relative to the parent.
318 gfx::Point origin = window_bounds.origin(); 389 gfx::Point origin = window_bounds.origin();
319 aura::Window::ConvertPointToTarget(window_->GetRootWindow(), 390 aura::Window::ConvertPointToTarget(window_->GetRootWindow(),
320 window_->parent(), &origin); 391 window_->parent(), &origin);
321 window_bounds.set_origin(origin); 392 window_bounds.set_origin(origin);
322 window_->SetBounds(window_bounds); 393 window_->SetBounds(window_bounds);
323 } 394 }
324 395
325 void NativeWidgetAura::GetWindowPlacement( 396 void NativeWidgetAndroid::GetWindowPlacement(
326 gfx::Rect* bounds, 397 gfx::Rect* bounds,
327 ui::WindowShowState* show_state) const { 398 ui::WindowShowState* show_state) const {
328 // The interface specifies returning restored bounds, not current bounds. 399 // The interface specifies returning restored bounds, not current bounds.
mfomitchev 2015/11/06 16:45:51 ditto
bshe 2015/11/11 00:38:30 Done.
329 *bounds = GetRestoredBounds(); 400 *bounds = GetRestoredBounds();
330 *show_state = window_ ? window_->GetProperty(aura::client::kShowStateKey) : 401 *show_state = window_ ? window_->GetProperty(aura::client::kShowStateKey)
331 ui::SHOW_STATE_DEFAULT; 402 : ui::SHOW_STATE_DEFAULT;
332 } 403 }
333 404
334 bool NativeWidgetAura::SetWindowTitle(const base::string16& title) { 405 bool NativeWidgetAndroid::SetWindowTitle(const base::string16& title) {
335 if (!window_) 406 if (!window_)
mfomitchev 2015/11/06 16:45:51 window_ can't be null?
bshe 2015/11/11 00:38:30 Done.
336 return false; 407 return false;
337 if (window_->title() == title) 408 if (window_->title() == title)
338 return false; 409 return false;
339 window_->SetTitle(title); 410 window_->SetTitle(title);
340 return true; 411 return true;
341 } 412 }
342 413
343 void NativeWidgetAura::SetWindowIcons(const gfx::ImageSkia& window_icon, 414 void NativeWidgetAndroid::SetWindowIcons(const gfx::ImageSkia& window_icon,
344 const gfx::ImageSkia& app_icon) { 415 const gfx::ImageSkia& app_icon) {
345 // Aura doesn't have window icons. 416 // Aura doesn't have window icons.
mfomitchev 2015/11/06 16:45:50 DesktopNativeWidgetAura has something for this, so
bshe 2015/11/11 00:38:30 Done.
346 } 417 }
347 418
348 void NativeWidgetAura::InitModalType(ui::ModalType modal_type) { 419 void NativeWidgetAndroid::InitModalType(ui::ModalType modal_type) {
349 if (modal_type != ui::MODAL_TYPE_NONE) 420 if (modal_type != ui::MODAL_TYPE_NONE)
350 window_->SetProperty(aura::client::kModalKey, modal_type); 421 window_->SetProperty(aura::client::kModalKey, modal_type);
351 } 422 }
352 423
353 gfx::Rect NativeWidgetAura::GetWindowBoundsInScreen() const { 424 gfx::Rect NativeWidgetAndroid::GetWindowBoundsInScreen() const {
354 return window_ ? window_->GetBoundsInScreen() : gfx::Rect(); 425 return window_ ? window_->GetBoundsInScreen() : gfx::Rect();
355 } 426 }
356 427
357 gfx::Rect NativeWidgetAura::GetClientAreaBoundsInScreen() const { 428 gfx::Rect NativeWidgetAndroid::GetClientAreaBoundsInScreen() const {
358 // View-to-screen coordinate system transformations depend on this returning 429 // View-to-screen coordinate system transformations depend on this returning
359 // the full window bounds, for example View::ConvertPointToScreen(). 430 // the full window bounds, for example View::ConvertPointToScreen().
360 return window_ ? window_->GetBoundsInScreen() : gfx::Rect(); 431 return window_ ? window_->GetBoundsInScreen() : gfx::Rect();
361 } 432 }
362 433
363 gfx::Rect NativeWidgetAura::GetRestoredBounds() const { 434 gfx::Rect NativeWidgetAndroid::GetRestoredBounds() const {
364 if (!window_) 435 if (!window_)
mfomitchev 2015/11/06 16:45:50 Same as CenterWindow and other top-level sizing/po
bshe 2015/11/11 00:38:30 Done.
365 return gfx::Rect(); 436 return gfx::Rect();
366 437
367 // Restored bounds should only be relevant if the window is minimized, 438 // Restored bounds should only be relevant if the window is minimized,
368 // maximized, fullscreen or docked. However, in some places the code expects 439 // maximized, fullscreen or docked. However, in some places the code expects
369 // GetRestoredBounds() to return the current window bounds if the window is 440 // GetRestoredBounds() to return the current window bounds if the window is
370 // not in either state. 441 // not in either state.
371 if (IsMinimized() || IsMaximized() || IsFullscreen()) { 442 if (IsMinimized() || IsMaximized() || IsFullscreen()) {
372 // Restore bounds are in screen coordinates, no need to convert. 443 // Restore bounds are in screen coordinates, no need to convert.
373 gfx::Rect* restore_bounds = 444 gfx::Rect* restore_bounds =
374 window_->GetProperty(aura::client::kRestoreBoundsKey); 445 window_->GetProperty(aura::client::kRestoreBoundsKey);
375 if (restore_bounds) 446 if (restore_bounds)
376 return *restore_bounds; 447 return *restore_bounds;
377 } 448 }
378 gfx::Rect bounds = window_->GetBoundsInScreen(); 449 gfx::Rect bounds = window_->GetBoundsInScreen();
379 if (IsDocked()) { 450 if (IsDocked()) {
380 // Restore bounds are in screen coordinates, no need to convert. 451 // Restore bounds are in screen coordinates, no need to convert.
381 gfx::Rect* restore_bounds = 452 gfx::Rect* restore_bounds =
382 window_->GetProperty(aura::client::kRestoreBoundsKey); 453 window_->GetProperty(aura::client::kRestoreBoundsKey);
383 // Use current window horizontal offset origin in order to preserve docked 454 // Use current window horizontal offset origin in order to preserve docked
384 // alignment but preserve restored size and vertical offset for the time 455 // alignment but preserve restored size and vertical offset for the time
385 // when the |window_| gets undocked. 456 // when the |window_| gets undocked.
386 if (restore_bounds) { 457 if (restore_bounds) {
387 bounds.set_size(restore_bounds->size()); 458 bounds.set_size(restore_bounds->size());
388 bounds.set_y(restore_bounds->y()); 459 bounds.set_y(restore_bounds->y());
389 } 460 }
390 } 461 }
391 return bounds; 462 return bounds;
392 } 463 }
393 464
394 void NativeWidgetAura::SetBounds(const gfx::Rect& bounds) { 465 void NativeWidgetAndroid::SetBounds(const gfx::Rect& bounds) {
395 if (!window_) 466 if (!window_)
396 return; 467 return;
397 468
398 aura::Window* root = window_->GetRootWindow(); 469 aura::Window* root = window_->GetRootWindow();
399 if (root) { 470 if (root) {
400 aura::client::ScreenPositionClient* screen_position_client = 471 aura::client::ScreenPositionClient* screen_position_client =
401 aura::client::GetScreenPositionClient(root); 472 aura::client::GetScreenPositionClient(root);
402 if (screen_position_client) { 473 if (screen_position_client) {
403 gfx::Display dst_display = 474 gfx::Display dst_display =
404 gfx::Screen::GetScreenFor(window_)->GetDisplayMatching(bounds); 475 gfx::Screen::GetScreenFor(window_)->GetDisplayMatching(bounds);
405 screen_position_client->SetBounds(window_, bounds, dst_display); 476 screen_position_client->SetBounds(window_, bounds, dst_display);
406 return; 477 return;
407 } 478 }
408 } 479 }
409 window_->SetBounds(bounds); 480 window_->SetBounds(bounds);
410 } 481 }
411 482
412 void NativeWidgetAura::SetSize(const gfx::Size& size) { 483 void NativeWidgetAndroid::SetSize(const gfx::Size& size) {
413 if (window_) 484 if (window_)
414 window_->SetBounds(gfx::Rect(window_->bounds().origin(), size)); 485 window_->SetBounds(gfx::Rect(window_->bounds().origin(), size));
415 } 486 }
416 487
417 void NativeWidgetAura::StackAbove(gfx::NativeView native_view) { 488 void NativeWidgetAndroid::StackAbove(gfx::NativeView native_view) {
418 if (window_ && window_->parent() && 489 if (window_ && window_->parent() &&
419 window_->parent() == native_view->parent()) 490 window_->parent() == native_view->parent())
420 window_->parent()->StackChildAbove(window_, native_view); 491 window_->parent()->StackChildAbove(window_, native_view);
421 } 492 }
422 493
423 void NativeWidgetAura::StackAtTop() { 494 void NativeWidgetAndroid::StackAtTop() {
424 if (window_) 495 if (window_)
425 window_->parent()->StackChildAtTop(window_); 496 window_->parent()->StackChildAtTop(window_);
426 } 497 }
427 498
428 void NativeWidgetAura::StackBelow(gfx::NativeView native_view) { 499 void NativeWidgetAndroid::StackBelow(gfx::NativeView native_view) {
429 if (window_ && window_->parent() && 500 if (window_ && window_->parent() &&
430 window_->parent() == native_view->parent()) 501 window_->parent() == native_view->parent())
431 window_->parent()->StackChildBelow(window_, native_view); 502 window_->parent()->StackChildBelow(window_, native_view);
432 } 503 }
433 504
434 void NativeWidgetAura::SetShape(SkRegion* region) { 505 void NativeWidgetAndroid::SetShape(SkRegion* region) {
435 if (window_) 506 if (window_)
436 window_->layer()->SetAlphaShape(make_scoped_ptr(region)); 507 window_->layer()->SetAlphaShape(make_scoped_ptr(region));
437 else 508 else
438 delete region; 509 delete region;
439 } 510 }
440 511
441 void NativeWidgetAura::Close() { 512 void NativeWidgetAndroid::Close() {
442 // |window_| may already be deleted by parent window. This can happen 513 // |window_| may already be deleted by parent window. This can happen
443 // when this widget is child widget or has transient parent 514 // when this widget is child widget or has transient parent
444 // and ownership is WIDGET_OWNS_NATIVE_WIDGET. 515 // and ownership is WIDGET_OWNS_NATIVE_WIDGET.
445 DCHECK(window_ || 516 DCHECK(window_ ||
446 ownership_ == Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET); 517 ownership_ == Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET);
447 if (window_) { 518 if (window_) {
448 window_->SuppressPaint(); 519 window_->SuppressPaint();
449 Hide(); 520 Hide();
450 window_->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_NONE); 521 window_->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_NONE);
451 } 522 }
452 523
453 if (!close_widget_factory_.HasWeakPtrs()) { 524 if (!close_widget_factory_.HasWeakPtrs()) {
454 base::MessageLoop::current()->PostTask( 525 base::MessageLoop::current()->PostTask(
455 FROM_HERE, 526 FROM_HERE, base::Bind(&NativeWidgetAndroid::CloseNow,
456 base::Bind(&NativeWidgetAura::CloseNow, 527 close_widget_factory_.GetWeakPtr()));
457 close_widget_factory_.GetWeakPtr()));
458 } 528 }
459 } 529 }
460 530
461 void NativeWidgetAura::CloseNow() { 531 void NativeWidgetAndroid::CloseNow() {
462 delete window_; 532 delete window_;
mfomitchev 2015/11/06 16:45:51 see Sadrul's comment
bshe 2015/11/11 00:38:30 Done.
463 } 533 }
464 534
465 void NativeWidgetAura::Show() { 535 void NativeWidgetAndroid::Show() {
466 ShowWithWindowState(ui::SHOW_STATE_NORMAL); 536 ShowWithWindowState(ui::SHOW_STATE_NORMAL);
467 } 537 }
468 538
469 void NativeWidgetAura::Hide() { 539 void NativeWidgetAndroid::Hide() {
470 if (window_) 540 if (window_)
471 window_->Hide(); 541 window_->Hide();
472 } 542 }
473 543
474 void NativeWidgetAura::ShowMaximizedWithBounds( 544 void NativeWidgetAndroid::ShowMaximizedWithBounds(
475 const gfx::Rect& restored_bounds) { 545 const gfx::Rect& restored_bounds) {
476 SetRestoreBounds(window_, restored_bounds); 546 SetRestoreBounds(window_, restored_bounds);
477 ShowWithWindowState(ui::SHOW_STATE_MAXIMIZED); 547 ShowWithWindowState(ui::SHOW_STATE_MAXIMIZED);
478 } 548 }
479 549
480 void NativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) { 550 void NativeWidgetAndroid::ShowWithWindowState(ui::WindowShowState state) {
481 if (!window_) 551 if (!window_)
482 return; 552 return;
483 553
484 if (state == ui::SHOW_STATE_MAXIMIZED || state == ui::SHOW_STATE_FULLSCREEN || 554 if (state == ui::SHOW_STATE_MAXIMIZED || state == ui::SHOW_STATE_FULLSCREEN ||
485 state == ui::SHOW_STATE_DOCKED) { 555 state == ui::SHOW_STATE_DOCKED) {
486 window_->SetProperty(aura::client::kShowStateKey, state); 556 window_->SetProperty(aura::client::kShowStateKey, state);
487 } 557 }
488 window_->Show(); 558 window_->Show();
489 if (delegate_->CanActivate()) { 559 if (delegate_->CanActivate()) {
490 if (state != ui::SHOW_STATE_INACTIVE) 560 if (state != ui::SHOW_STATE_INACTIVE)
491 Activate(); 561 Activate();
492 // SetInitialFocus() should be always be called, even for 562 // SetInitialFocus() should be always be called, even for
493 // SHOW_STATE_INACTIVE. If the window has to stay inactive, the method will 563 // SHOW_STATE_INACTIVE. If the window has to stay inactive, the method will
494 // do the right thing. 564 // do the right thing.
495 SetInitialFocus(state); 565 SetInitialFocus(state);
496 } 566 }
497 } 567 }
498 568
499 bool NativeWidgetAura::IsVisible() const { 569 bool NativeWidgetAndroid::IsVisible() const {
500 return window_ && window_->IsVisible(); 570 return window_ && window_->IsVisible();
501 } 571 }
502 572
503 void NativeWidgetAura::Activate() { 573 void NativeWidgetAndroid::Activate() {
504 if (!window_) 574 if (!window_)
505 return; 575 return;
506 576
507 // We don't necessarily have a root window yet. This can happen with 577 // We don't necessarily have a root window yet. This can happen with
508 // constrained windows. 578 // constrained windows.
509 if (window_->GetRootWindow()) { 579 if (window_->GetRootWindow()) {
510 aura::client::GetActivationClient(window_->GetRootWindow())->ActivateWindow( 580 aura::client::GetActivationClient(window_->GetRootWindow())
511 window_); 581 ->ActivateWindow(window_);
512 } 582 }
513 if (window_->GetProperty(aura::client::kDrawAttentionKey)) 583 if (window_->GetProperty(aura::client::kDrawAttentionKey))
514 window_->SetProperty(aura::client::kDrawAttentionKey, false); 584 window_->SetProperty(aura::client::kDrawAttentionKey, false);
515 } 585 }
516 586
517 void NativeWidgetAura::Deactivate() { 587 void NativeWidgetAndroid::Deactivate() {
518 if (!window_) 588 if (!window_)
519 return; 589 return;
520 aura::client::GetActivationClient(window_->GetRootWindow())->DeactivateWindow( 590 aura::client::GetActivationClient(window_->GetRootWindow())
521 window_); 591 ->DeactivateWindow(window_);
522 } 592 }
523 593
524 bool NativeWidgetAura::IsActive() const { 594 bool NativeWidgetAndroid::IsActive() const {
525 return window_ && wm::IsActiveWindow(window_); 595 return window_ && wm::IsActiveWindow(window_);
526 } 596 }
527 597
528 void NativeWidgetAura::SetAlwaysOnTop(bool on_top) { 598 void NativeWidgetAndroid::SetAlwaysOnTop(bool on_top) {
529 if (window_) 599 if (window_)
530 window_->SetProperty(aura::client::kAlwaysOnTopKey, on_top); 600 window_->SetProperty(aura::client::kAlwaysOnTopKey, on_top);
531 } 601 }
532 602
533 bool NativeWidgetAura::IsAlwaysOnTop() const { 603 bool NativeWidgetAndroid::IsAlwaysOnTop() const {
534 return window_ && window_->GetProperty(aura::client::kAlwaysOnTopKey); 604 return window_ && window_->GetProperty(aura::client::kAlwaysOnTopKey);
535 } 605 }
536 606
537 void NativeWidgetAura::SetVisibleOnAllWorkspaces(bool always_visible) { 607 void NativeWidgetAndroid::SetVisibleOnAllWorkspaces(bool always_visible) {
538 // Not implemented on chromeos or for child widgets. 608 // Not implemented on chromeos or for child widgets.
539 } 609 }
540 610
541 void NativeWidgetAura::Maximize() { 611 void NativeWidgetAndroid::Maximize() {
542 if (window_) 612 if (window_)
543 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 613 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
544 } 614 }
545 615
546 void NativeWidgetAura::Minimize() { 616 void NativeWidgetAndroid::Minimize() {
547 if (window_) 617 if (window_)
548 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); 618 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
549 } 619 }
550 620
551 bool NativeWidgetAura::IsMaximized() const { 621 bool NativeWidgetAndroid::IsMaximized() const {
552 return window_ && window_->GetProperty(aura::client::kShowStateKey) == 622 return window_ &&
553 ui::SHOW_STATE_MAXIMIZED; 623 window_->GetProperty(aura::client::kShowStateKey) ==
624 ui::SHOW_STATE_MAXIMIZED;
554 } 625 }
555 626
556 bool NativeWidgetAura::IsMinimized() const { 627 bool NativeWidgetAndroid::IsMinimized() const {
557 return window_ && window_->GetProperty(aura::client::kShowStateKey) == 628 return window_ &&
558 ui::SHOW_STATE_MINIMIZED; 629 window_->GetProperty(aura::client::kShowStateKey) ==
630 ui::SHOW_STATE_MINIMIZED;
559 } 631 }
560 632
561 void NativeWidgetAura::Restore() { 633 void NativeWidgetAndroid::Restore() {
562 if (window_) 634 if (window_)
563 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 635 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
564 } 636 }
565 637
566 void NativeWidgetAura::SetFullscreen(bool fullscreen) { 638 void NativeWidgetAndroid::SetFullscreen(bool fullscreen) {
567 if (!window_ || IsFullscreen() == fullscreen) 639 if (!window_ || IsFullscreen() == fullscreen)
568 return; // Nothing to do. 640 return; // Nothing to do.
569 641
570 // Save window state before entering full screen so that it could restored 642 // Save window state before entering full screen so that it could restored
571 // when exiting full screen. 643 // when exiting full screen.
572 if (fullscreen) 644 if (fullscreen)
573 saved_window_state_ = window_->GetProperty(aura::client::kShowStateKey); 645 saved_window_state_ = window_->GetProperty(aura::client::kShowStateKey);
574 646
575 window_->SetProperty( 647 window_->SetProperty(
576 aura::client::kShowStateKey, 648 aura::client::kShowStateKey,
577 fullscreen ? ui::SHOW_STATE_FULLSCREEN : saved_window_state_); 649 fullscreen ? ui::SHOW_STATE_FULLSCREEN : saved_window_state_);
578 } 650 }
579 651
580 bool NativeWidgetAura::IsFullscreen() const { 652 bool NativeWidgetAndroid::IsFullscreen() const {
581 return window_ && window_->GetProperty(aura::client::kShowStateKey) == 653 return window_ &&
582 ui::SHOW_STATE_FULLSCREEN; 654 window_->GetProperty(aura::client::kShowStateKey) ==
655 ui::SHOW_STATE_FULLSCREEN;
583 } 656 }
584 657
585 void NativeWidgetAura::SetOpacity(unsigned char opacity) { 658 void NativeWidgetAndroid::SetOpacity(unsigned char opacity) {
586 if (window_) 659 if (window_)
587 window_->layer()->SetOpacity(opacity / 255.0); 660 window_->layer()->SetOpacity(opacity / 255.0);
588 } 661 }
589 662
590 void NativeWidgetAura::SetUseDragFrame(bool use_drag_frame) { 663 void NativeWidgetAndroid::SetUseDragFrame(bool use_drag_frame) {
591 NOTIMPLEMENTED(); 664 NOTIMPLEMENTED();
592 } 665 }
593 666
594 void NativeWidgetAura::FlashFrame(bool flash) { 667 void NativeWidgetAndroid::FlashFrame(bool flash) {
595 if (window_) 668 if (window_)
596 window_->SetProperty(aura::client::kDrawAttentionKey, flash); 669 window_->SetProperty(aura::client::kDrawAttentionKey, flash);
597 } 670 }
598 671
599 void NativeWidgetAura::RunShellDrag(View* view, 672 void NativeWidgetAndroid::RunShellDrag(
600 const ui::OSExchangeData& data, 673 View* view,
601 const gfx::Point& location, 674 const ui::OSExchangeData& data,
602 int operation, 675 const gfx::Point& location,
603 ui::DragDropTypes::DragEventSource source) { 676 int operation,
677 ui::DragDropTypes::DragEventSource source) {
604 if (window_) 678 if (window_)
605 views::RunShellDrag(window_, data, location, operation, source); 679 views::RunShellDrag(window_, data, location, operation, source);
606 } 680 }
607 681
608 void NativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) { 682 void NativeWidgetAndroid::SchedulePaintInRect(const gfx::Rect& rect) {
609 if (window_) 683 if (window_)
610 window_->SchedulePaintInRect(rect); 684 window_->SchedulePaintInRect(rect);
611 } 685 }
612 686
613 void NativeWidgetAura::SetCursor(gfx::NativeCursor cursor) { 687 void NativeWidgetAndroid::SetCursor(gfx::NativeCursor cursor) {
614 cursor_ = cursor; 688 cursor_ = cursor;
615 aura::client::CursorClient* cursor_client = 689 aura::client::CursorClient* cursor_client =
616 aura::client::GetCursorClient(window_->GetRootWindow()); 690 aura::client::GetCursorClient(window_->GetRootWindow());
617 if (cursor_client) 691 if (cursor_client)
618 cursor_client->SetCursor(cursor); 692 cursor_client->SetCursor(cursor);
619 } 693 }
620 694
621 bool NativeWidgetAura::IsMouseEventsEnabled() const { 695 bool NativeWidgetAndroid::IsMouseEventsEnabled() const {
622 if (!window_) 696 if (!window_)
623 return false; 697 return false;
624 aura::client::CursorClient* cursor_client = 698 aura::client::CursorClient* cursor_client =
625 aura::client::GetCursorClient(window_->GetRootWindow()); 699 aura::client::GetCursorClient(window_->GetRootWindow());
626 return cursor_client ? cursor_client->IsMouseEventsEnabled() : true; 700 return cursor_client ? cursor_client->IsMouseEventsEnabled() : true;
627 } 701 }
628 702
629 void NativeWidgetAura::ClearNativeFocus() { 703 void NativeWidgetAndroid::ClearNativeFocus() {
630 aura::client::FocusClient* client = aura::client::GetFocusClient(window_); 704 aura::client::FocusClient* client = aura::client::GetFocusClient(window_);
631 if (window_ && client && window_->Contains(client->GetFocusedWindow())) 705 if (window_ && client && window_->Contains(client->GetFocusedWindow()))
632 client->ResetFocusWithinActiveWindow(window_); 706 client->ResetFocusWithinActiveWindow(window_);
633 } 707 }
634 708
635 gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const { 709 gfx::Rect NativeWidgetAndroid::GetWorkAreaBoundsInScreen() const {
636 if (!window_) 710 if (!window_)
637 return gfx::Rect(); 711 return gfx::Rect();
638 return gfx::Screen::GetScreenFor(window_)-> 712 return gfx::Screen::GetScreenFor(window_)
639 GetDisplayNearestWindow(window_).work_area(); 713 ->GetDisplayNearestWindow(window_)
714 .work_area();
640 } 715 }
641 716
642 Widget::MoveLoopResult NativeWidgetAura::RunMoveLoop( 717 Widget::MoveLoopResult NativeWidgetAndroid::RunMoveLoop(
643 const gfx::Vector2d& drag_offset, 718 const gfx::Vector2d& drag_offset,
644 Widget::MoveLoopSource source, 719 Widget::MoveLoopSource source,
645 Widget::MoveLoopEscapeBehavior escape_behavior) { 720 Widget::MoveLoopEscapeBehavior escape_behavior) {
646 // |escape_behavior| is only needed on windows when running the native message 721 // |escape_behavior| is only needed on windows when running the native message
647 // loop. 722 // loop.
648 if (!window_ || !window_->GetRootWindow()) 723 if (!window_ || !window_->GetRootWindow())
649 return Widget::MOVE_LOOP_CANCELED; 724 return Widget::MOVE_LOOP_CANCELED;
650 aura::client::WindowMoveClient* move_client = 725 aura::client::WindowMoveClient* move_client =
651 aura::client::GetWindowMoveClient(window_->GetRootWindow()); 726 aura::client::GetWindowMoveClient(window_->GetRootWindow());
652 if (!move_client) 727 if (!move_client)
653 return Widget::MOVE_LOOP_CANCELED; 728 return Widget::MOVE_LOOP_CANCELED;
654 729
655 SetCapture(); 730 SetCapture();
656 aura::client::WindowMoveSource window_move_source = 731 aura::client::WindowMoveSource window_move_source =
657 source == Widget::MOVE_LOOP_SOURCE_MOUSE ? 732 source == Widget::MOVE_LOOP_SOURCE_MOUSE
658 aura::client::WINDOW_MOVE_SOURCE_MOUSE : 733 ? aura::client::WINDOW_MOVE_SOURCE_MOUSE
659 aura::client::WINDOW_MOVE_SOURCE_TOUCH; 734 : aura::client::WINDOW_MOVE_SOURCE_TOUCH;
660 if (move_client->RunMoveLoop(window_, drag_offset, window_move_source) == 735 if (move_client->RunMoveLoop(window_, drag_offset, window_move_source) ==
661 aura::client::MOVE_SUCCESSFUL) { 736 aura::client::MOVE_SUCCESSFUL) {
662 return Widget::MOVE_LOOP_SUCCESSFUL; 737 return Widget::MOVE_LOOP_SUCCESSFUL;
663 } 738 }
664 return Widget::MOVE_LOOP_CANCELED; 739 return Widget::MOVE_LOOP_CANCELED;
665 } 740 }
666 741
667 void NativeWidgetAura::EndMoveLoop() { 742 void NativeWidgetAndroid::EndMoveLoop() {
668 if (!window_ || !window_->GetRootWindow()) 743 if (!window_ || !window_->GetRootWindow())
669 return; 744 return;
670 aura::client::WindowMoveClient* move_client = 745 aura::client::WindowMoveClient* move_client =
671 aura::client::GetWindowMoveClient(window_->GetRootWindow()); 746 aura::client::GetWindowMoveClient(window_->GetRootWindow());
672 if (move_client) 747 if (move_client)
673 move_client->EndMoveLoop(); 748 move_client->EndMoveLoop();
674 } 749 }
675 750
676 void NativeWidgetAura::SetVisibilityChangedAnimationsEnabled(bool value) { 751 void NativeWidgetAndroid::SetVisibilityChangedAnimationsEnabled(bool value) {
677 if (window_) 752 if (window_)
678 window_->SetProperty(aura::client::kAnimationsDisabledKey, !value); 753 window_->SetProperty(aura::client::kAnimationsDisabledKey, !value);
679 } 754 }
680 755
681 void NativeWidgetAura::SetVisibilityAnimationDuration( 756 void NativeWidgetAndroid::SetVisibilityAnimationDuration(
682 const base::TimeDelta& duration) { 757 const base::TimeDelta& duration) {
683 wm::SetWindowVisibilityAnimationDuration(window_, duration); 758 wm::SetWindowVisibilityAnimationDuration(window_, duration);
684 } 759 }
685 760
686 void NativeWidgetAura::SetVisibilityAnimationTransition( 761 void NativeWidgetAndroid::SetVisibilityAnimationTransition(
687 Widget::VisibilityTransition transition) { 762 Widget::VisibilityTransition transition) {
688 wm::WindowVisibilityAnimationTransition wm_transition = wm::ANIMATE_NONE; 763 wm::WindowVisibilityAnimationTransition wm_transition = wm::ANIMATE_NONE;
689 switch (transition) { 764 switch (transition) {
690 case Widget::ANIMATE_SHOW: 765 case Widget::ANIMATE_SHOW:
691 wm_transition = wm::ANIMATE_SHOW; 766 wm_transition = wm::ANIMATE_SHOW;
692 break; 767 break;
693 case Widget::ANIMATE_HIDE: 768 case Widget::ANIMATE_HIDE:
694 wm_transition = wm::ANIMATE_HIDE; 769 wm_transition = wm::ANIMATE_HIDE;
695 break; 770 break;
696 case Widget::ANIMATE_BOTH: 771 case Widget::ANIMATE_BOTH:
697 wm_transition = wm::ANIMATE_BOTH; 772 wm_transition = wm::ANIMATE_BOTH;
698 break; 773 break;
699 case Widget::ANIMATE_NONE: 774 case Widget::ANIMATE_NONE:
700 wm_transition = wm::ANIMATE_NONE; 775 wm_transition = wm::ANIMATE_NONE;
701 break; 776 break;
702 } 777 }
703 wm::SetWindowVisibilityAnimationTransition(window_, wm_transition); 778 wm::SetWindowVisibilityAnimationTransition(window_, wm_transition);
704 } 779 }
705 780
706 ui::NativeTheme* NativeWidgetAura::GetNativeTheme() const { 781 ui::NativeTheme* NativeWidgetAndroid::GetNativeTheme() const {
707 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
708 return DesktopWindowTreeHost::GetNativeTheme(window_);
709 #else
710 return ui::NativeThemeAura::instance(); 782 return ui::NativeThemeAura::instance();
711 #endif
712 } 783 }
713 784
714 void NativeWidgetAura::OnRootViewLayout() { 785 void NativeWidgetAndroid::OnRootViewLayout() {}
715 }
716 786
717 bool NativeWidgetAura::IsTranslucentWindowOpacitySupported() const { 787 bool NativeWidgetAndroid::IsTranslucentWindowOpacitySupported() const {
718 return true; 788 return true;
719 } 789 }
720 790
721 void NativeWidgetAura::OnSizeConstraintsChanged() { 791 void NativeWidgetAndroid::OnSizeConstraintsChanged() {
722 window_->SetProperty(aura::client::kCanMaximizeKey, 792 window_->SetProperty(aura::client::kCanMaximizeKey,
723 GetWidget()->widget_delegate()->CanMaximize()); 793 GetWidget()->widget_delegate()->CanMaximize());
724 window_->SetProperty(aura::client::kCanMinimizeKey, 794 window_->SetProperty(aura::client::kCanMinimizeKey,
725 GetWidget()->widget_delegate()->CanMinimize()); 795 GetWidget()->widget_delegate()->CanMinimize());
726 window_->SetProperty(aura::client::kCanResizeKey, 796 window_->SetProperty(aura::client::kCanResizeKey,
727 GetWidget()->widget_delegate()->CanResize()); 797 GetWidget()->widget_delegate()->CanResize());
728 } 798 }
729 799
730 void NativeWidgetAura::RepostNativeEvent(gfx::NativeEvent native_event) { 800 void NativeWidgetAndroid::RepostNativeEvent(gfx::NativeEvent native_event) {
731 OnEvent(native_event); 801 OnEvent(native_event);
732 } 802 }
733 803
734 //////////////////////////////////////////////////////////////////////////////// 804 ////////////////////////////////////////////////////////////////////////////////
735 // NativeWidgetAura, aura::WindowDelegate implementation: 805 // NativeWidgetAndroid, aura::WindowDelegate implementation:
736 806
737 gfx::Size NativeWidgetAura::GetMinimumSize() const { 807 gfx::Size NativeWidgetAndroid::GetMinimumSize() const {
738 return delegate_->GetMinimumSize(); 808 return delegate_->GetMinimumSize();
739 } 809 }
740 810
741 gfx::Size NativeWidgetAura::GetMaximumSize() const { 811 gfx::Size NativeWidgetAndroid::GetMaximumSize() const {
742 // If a window have a maximum size, the window should not be 812 // If a window have a maximum size, the window should not be
743 // maximizable. 813 // maximizable.
744 DCHECK(delegate_->GetMaximumSize().IsEmpty() || 814 DCHECK(delegate_->GetMaximumSize().IsEmpty() ||
745 !window_->GetProperty(aura::client::kCanMaximizeKey)); 815 !window_->GetProperty(aura::client::kCanMaximizeKey));
746 return delegate_->GetMaximumSize(); 816 return delegate_->GetMaximumSize();
747 } 817 }
748 818
749 void NativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds, 819 void NativeWidgetAndroid::OnBoundsChanged(const gfx::Rect& old_bounds,
750 const gfx::Rect& new_bounds) { 820 const gfx::Rect& new_bounds) {
751 // Assume that if the old bounds was completely empty a move happened. This 821 // Assume that if the old bounds was completely empty a move happened. This
752 // handles the case of a maximize animation acquiring the layer (acquiring a 822 // handles the case of a maximize animation acquiring the layer (acquiring a
753 // layer results in clearing the bounds). 823 // layer results in clearing the bounds).
754 if (old_bounds.origin() != new_bounds.origin() || 824 if (old_bounds.origin() != new_bounds.origin() ||
755 (old_bounds == gfx::Rect(0, 0, 0, 0) && !new_bounds.IsEmpty())) { 825 (old_bounds == gfx::Rect(0, 0, 0, 0) && !new_bounds.IsEmpty())) {
756 delegate_->OnNativeWidgetMove(); 826 delegate_->OnNativeWidgetMove();
757 } 827 }
758 if (old_bounds.size() != new_bounds.size()) 828 if (old_bounds.size() != new_bounds.size())
759 delegate_->OnNativeWidgetSizeChanged(new_bounds.size()); 829 delegate_->OnNativeWidgetSizeChanged(new_bounds.size());
760 } 830 }
761 831
762 gfx::NativeCursor NativeWidgetAura::GetCursor(const gfx::Point& point) { 832 gfx::NativeCursor NativeWidgetAndroid::GetCursor(const gfx::Point& point) {
763 return cursor_; 833 return cursor_;
764 } 834 }
765 835
766 int NativeWidgetAura::GetNonClientComponent(const gfx::Point& point) const { 836 int NativeWidgetAndroid::GetNonClientComponent(const gfx::Point& point) const {
767 return delegate_->GetNonClientComponent(point); 837 return delegate_->GetNonClientComponent(point);
768 } 838 }
769 839
770 bool NativeWidgetAura::ShouldDescendIntoChildForEventHandling( 840 bool NativeWidgetAndroid::ShouldDescendIntoChildForEventHandling(
771 aura::Window* child, 841 aura::Window* child,
772 const gfx::Point& location) { 842 const gfx::Point& location) {
773 views::WidgetDelegate* widget_delegate = GetWidget()->widget_delegate(); 843 views::WidgetDelegate* widget_delegate = GetWidget()->widget_delegate();
774 if (widget_delegate && 844 if (widget_delegate &&
775 !widget_delegate->ShouldDescendIntoChildForEventHandling(child, location)) 845 !widget_delegate->ShouldDescendIntoChildForEventHandling(child, location))
776 return false; 846 return false;
777 847
778 // Don't descend into |child| if there is a view with a Layer that contains 848 // Don't descend into |child| if there is a view with a Layer that contains
779 // the point and is stacked above |child|s layer. 849 // the point and is stacked above |child|s layer.
780 typedef std::vector<ui::Layer*> Layers; 850 typedef std::vector<ui::Layer*> Layers;
781 const Layers& root_layers(delegate_->GetRootLayers()); 851 const Layers& root_layers(delegate_->GetRootLayers());
782 if (root_layers.empty()) 852 if (root_layers.empty())
(...skipping 12 matching lines...) Expand all
795 Layers::const_iterator root_layer_iter( 865 Layers::const_iterator root_layer_iter(
796 std::find(window_->layer()->children().begin(), 866 std::find(window_->layer()->children().begin(),
797 window_->layer()->children().end(), layer)); 867 window_->layer()->children().end(), layer));
798 if (root_layer_iter > child_layer_iter) 868 if (root_layer_iter > child_layer_iter)
799 return false; 869 return false;
800 } 870 }
801 } 871 }
802 return true; 872 return true;
803 } 873 }
804 874
805 bool NativeWidgetAura::CanFocus() { 875 bool NativeWidgetAndroid::CanFocus() {
806 return ShouldActivate(); 876 return ShouldActivate();
807 } 877 }
808 878
809 void NativeWidgetAura::OnCaptureLost() { 879 void NativeWidgetAndroid::OnCaptureLost() {
810 delegate_->OnMouseCaptureLost(); 880 delegate_->OnMouseCaptureLost();
811 } 881 }
812 882
813 void NativeWidgetAura::OnPaint(const ui::PaintContext& context) { 883 void NativeWidgetAndroid::OnPaint(const ui::PaintContext& context) {
814 delegate_->OnNativeWidgetPaint(context); 884 delegate_->OnNativeWidgetPaint(context);
815 } 885 }
816 886
817 void NativeWidgetAura::OnDeviceScaleFactorChanged(float device_scale_factor) { 887 void NativeWidgetAndroid::OnDeviceScaleFactorChanged(
888 float device_scale_factor) {
818 GetWidget()->DeviceScaleFactorChanged(device_scale_factor); 889 GetWidget()->DeviceScaleFactorChanged(device_scale_factor);
819 } 890 }
820 891
821 void NativeWidgetAura::OnWindowDestroying(aura::Window* window) { 892 void NativeWidgetAndroid::OnWindowDestroying(aura::Window* window) {
822 window_->RemoveObserver(this); 893 window_->RemoveObserver(this);
823 delegate_->OnNativeWidgetDestroying(); 894 delegate_->OnNativeWidgetDestroying();
824 895
825 // If the aura::Window is destroyed, we can no longer show tooltips. 896 // If the aura::Window is destroyed, we can no longer show tooltips.
826 tooltip_manager_.reset(); 897 tooltip_manager_.reset();
827 } 898 }
828 899
829 void NativeWidgetAura::OnWindowDestroyed(aura::Window* window) { 900 void NativeWidgetAndroid::OnWindowDestroyed(aura::Window* window) {
830 window_ = NULL; 901 window_ = NULL;
831 delegate_->OnNativeWidgetDestroyed(); 902 delegate_->OnNativeWidgetDestroyed();
832 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 903 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
833 delete this; 904 delete this;
834 } 905 }
835 906
836 void NativeWidgetAura::OnWindowTargetVisibilityChanged(bool visible) { 907 void NativeWidgetAndroid::OnWindowTargetVisibilityChanged(bool visible) {
837 delegate_->OnNativeWidgetVisibilityChanged(visible); 908 delegate_->OnNativeWidgetVisibilityChanged(visible);
838 } 909 }
839 910
840 bool NativeWidgetAura::HasHitTestMask() const { 911 bool NativeWidgetAndroid::HasHitTestMask() const {
841 return delegate_->HasHitTestMask(); 912 return delegate_->HasHitTestMask();
842 } 913 }
843 914
844 void NativeWidgetAura::GetHitTestMask(gfx::Path* mask) const { 915 void NativeWidgetAndroid::GetHitTestMask(gfx::Path* mask) const {
845 DCHECK(mask); 916 DCHECK(mask);
846 delegate_->GetHitTestMask(mask); 917 delegate_->GetHitTestMask(mask);
847 } 918 }
848 919
849 //////////////////////////////////////////////////////////////////////////////// 920 ////////////////////////////////////////////////////////////////////////////////
850 // NativeWidgetAura, aura::WindowObserver implementation: 921 // NativeWidgetAndroid, aura::WindowObserver implementation:
851 922
852 void NativeWidgetAura::OnWindowPropertyChanged(aura::Window* window, 923 void NativeWidgetAndroid::OnWindowPropertyChanged(aura::Window* window,
853 const void* key, 924 const void* key,
854 intptr_t old) { 925 intptr_t old) {
855 if (key == aura::client::kShowStateKey) 926 if (key == aura::client::kShowStateKey)
856 delegate_->OnNativeWidgetWindowShowStateChanged(); 927 delegate_->OnNativeWidgetWindowShowStateChanged();
857 } 928 }
858 929
859 //////////////////////////////////////////////////////////////////////////////// 930 ////////////////////////////////////////////////////////////////////////////////
860 // NativeWidgetAura, ui::EventHandler implementation: 931 // NativeWidgetAndroid, ui::EventHandler implementation:
861 932
862 void NativeWidgetAura::OnKeyEvent(ui::KeyEvent* event) { 933 void NativeWidgetAndroid::OnKeyEvent(ui::KeyEvent* event) {
863 DCHECK(window_); 934 DCHECK(window_);
864 // Renderer may send a key event back to us if the key event wasn't handled, 935 // Renderer may send a key event back to us if the key event wasn't handled,
865 // and the window may be invisible by that time. 936 // and the window may be invisible by that time.
866 if (!window_->IsVisible()) 937 if (!window_->IsVisible())
867 return; 938 return;
868 939
869 FocusManager* focus_manager = GetWidget()->GetFocusManager(); 940 FocusManager* focus_manager = GetWidget()->GetFocusManager();
870 delegate_->OnKeyEvent(event); 941 delegate_->OnKeyEvent(event);
871 if (!event->handled() && focus_manager) 942 if (!event->handled() && focus_manager)
872 focus_manager->OnKeyEvent(*event); 943 focus_manager->OnKeyEvent(*event);
873 event->SetHandled(); 944 event->SetHandled();
874 } 945 }
875 946
876 void NativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) { 947 void NativeWidgetAndroid::OnMouseEvent(ui::MouseEvent* event) {
877 DCHECK(window_); 948 DCHECK(window_);
878 DCHECK(window_->IsVisible()); 949 DCHECK(window_->IsVisible());
879 if (event->type() == ui::ET_MOUSEWHEEL) { 950 if (event->type() == ui::ET_MOUSEWHEEL) {
880 delegate_->OnMouseEvent(event); 951 delegate_->OnMouseEvent(event);
881 if (event->handled()) 952 if (event->handled())
882 return; 953 return;
883 } 954 }
884 955
885 if (tooltip_manager_.get()) 956 if (tooltip_manager_.get())
886 tooltip_manager_->UpdateTooltip(); 957 tooltip_manager_->UpdateTooltip();
887 TooltipManagerAura::UpdateTooltipManagerForCapture(GetWidget()); 958 TooltipManagerAura::UpdateTooltipManagerForCapture(GetWidget());
888 delegate_->OnMouseEvent(event); 959 delegate_->OnMouseEvent(event);
889 } 960 }
890 961
891 void NativeWidgetAura::OnScrollEvent(ui::ScrollEvent* event) { 962 void NativeWidgetAndroid::OnScrollEvent(ui::ScrollEvent* event) {
892 delegate_->OnScrollEvent(event); 963 delegate_->OnScrollEvent(event);
893 } 964 }
894 965
895 void NativeWidgetAura::OnGestureEvent(ui::GestureEvent* event) { 966 void NativeWidgetAndroid::OnGestureEvent(ui::GestureEvent* event) {
896 DCHECK(window_); 967 DCHECK(window_);
897 DCHECK(window_->IsVisible() || event->IsEndingEvent()); 968 DCHECK(window_->IsVisible() || event->IsEndingEvent());
898 delegate_->OnGestureEvent(event); 969 delegate_->OnGestureEvent(event);
899 } 970 }
900 971
901 //////////////////////////////////////////////////////////////////////////////// 972 ////////////////////////////////////////////////////////////////////////////////
902 // NativeWidgetAura, aura::client::ActivationDelegate implementation: 973 // NativeWidgetAndroid, aura::client::ActivationDelegate implementation:
903 974
904 bool NativeWidgetAura::ShouldActivate() const { 975 bool NativeWidgetAndroid::ShouldActivate() const {
905 return delegate_->CanActivate(); 976 return delegate_->CanActivate();
906 } 977 }
907 978
908 //////////////////////////////////////////////////////////////////////////////// 979 ////////////////////////////////////////////////////////////////////////////////
909 // NativeWidgetAura, aura::client::ActivationChangeObserver implementation: 980 // NativeWidgetAndroid, aura::client::ActivationChangeObserver implementation:
910 981
911 void NativeWidgetAura::OnWindowActivated( 982 void NativeWidgetAndroid::OnWindowActivated(
912 aura::client::ActivationChangeObserver::ActivationReason, 983 aura::client::ActivationChangeObserver::ActivationReason,
913 aura::Window* gained_active, 984 aura::Window* gained_active,
914 aura::Window* lost_active) { 985 aura::Window* lost_active) {
915 DCHECK(window_ == gained_active || window_ == lost_active); 986 DCHECK(window_ == gained_active || window_ == lost_active);
916 if (GetWidget()->GetFocusManager()) { 987 if (GetWidget()->GetFocusManager()) {
917 if (window_ == gained_active) 988 if (window_ == gained_active)
918 GetWidget()->GetFocusManager()->RestoreFocusedView(); 989 GetWidget()->GetFocusManager()->RestoreFocusedView();
919 else if (window_ == lost_active) 990 else if (window_ == lost_active)
920 GetWidget()->GetFocusManager()->StoreFocusedView(true); 991 GetWidget()->GetFocusManager()->StoreFocusedView(true);
921 } 992 }
922 delegate_->OnNativeWidgetActivationChanged(window_ == gained_active); 993 delegate_->OnNativeWidgetActivationChanged(window_ == gained_active);
923 } 994 }
924 995
925 //////////////////////////////////////////////////////////////////////////////// 996 ////////////////////////////////////////////////////////////////////////////////
926 // NativeWidgetAura, aura::client::FocusChangeObserver: 997 // NativeWidgetAndroid, aura::client::FocusChangeObserver:
927 998
928 void NativeWidgetAura::OnWindowFocused(aura::Window* gained_focus, 999 void NativeWidgetAndroid::OnWindowFocused(aura::Window* gained_focus,
929 aura::Window* lost_focus) { 1000 aura::Window* lost_focus) {
930 if (window_ == gained_focus) 1001 if (window_ == gained_focus)
931 delegate_->OnNativeFocus(); 1002 delegate_->OnNativeFocus();
932 else if (window_ == lost_focus) 1003 else if (window_ == lost_focus)
933 delegate_->OnNativeBlur(); 1004 delegate_->OnNativeBlur();
934 } 1005 }
935 1006
936 //////////////////////////////////////////////////////////////////////////////// 1007 ////////////////////////////////////////////////////////////////////////////////
937 // NativeWidgetAura, aura::WindowDragDropDelegate implementation: 1008 // NativeWidgetAndroid, aura::WindowDragDropDelegate implementation:
938 1009
939 void NativeWidgetAura::OnDragEntered(const ui::DropTargetEvent& event) { 1010 void NativeWidgetAndroid::OnDragEntered(const ui::DropTargetEvent& event) {
940 DCHECK(drop_helper_.get() != NULL); 1011 DCHECK(drop_helper_.get() != NULL);
941 last_drop_operation_ = drop_helper_->OnDragOver(event.data(), 1012 last_drop_operation_ = drop_helper_->OnDragOver(
942 event.location(), event.source_operations()); 1013 event.data(), event.location(), event.source_operations());
943 } 1014 }
944 1015
945 int NativeWidgetAura::OnDragUpdated(const ui::DropTargetEvent& event) { 1016 int NativeWidgetAndroid::OnDragUpdated(const ui::DropTargetEvent& event) {
946 DCHECK(drop_helper_.get() != NULL); 1017 DCHECK(drop_helper_.get() != NULL);
947 last_drop_operation_ = drop_helper_->OnDragOver(event.data(), 1018 last_drop_operation_ = drop_helper_->OnDragOver(
948 event.location(), event.source_operations()); 1019 event.data(), event.location(), event.source_operations());
949 return last_drop_operation_; 1020 return last_drop_operation_;
950 } 1021 }
951 1022
952 void NativeWidgetAura::OnDragExited() { 1023 void NativeWidgetAndroid::OnDragExited() {
953 DCHECK(drop_helper_.get() != NULL); 1024 DCHECK(drop_helper_.get() != NULL);
954 drop_helper_->OnDragExit(); 1025 drop_helper_->OnDragExit();
955 } 1026 }
956 1027
957 int NativeWidgetAura::OnPerformDrop(const ui::DropTargetEvent& event) { 1028 int NativeWidgetAndroid::OnPerformDrop(const ui::DropTargetEvent& event) {
958 DCHECK(drop_helper_.get() != NULL); 1029 DCHECK(drop_helper_.get() != NULL);
959 return drop_helper_->OnDrop(event.data(), event.location(), 1030 return drop_helper_->OnDrop(event.data(), event.location(),
960 last_drop_operation_); 1031 last_drop_operation_);
961 } 1032 }
962 1033
963 //////////////////////////////////////////////////////////////////////////////// 1034 ////////////////////////////////////////////////////////////////////////////////
964 // NativeWidgetAura, protected: 1035 // NativeWidgetAndroid, protected:
965 1036
966 NativeWidgetAura::~NativeWidgetAura() { 1037 NativeWidgetAndroid::~NativeWidgetAndroid() {
967 destroying_ = true; 1038 destroying_ = true;
968 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 1039 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
969 delete delegate_; 1040 delete delegate_;
970 else 1041 else
971 CloseNow(); 1042 CloseNow();
972 } 1043 }
973 1044
974 //////////////////////////////////////////////////////////////////////////////// 1045 ////////////////////////////////////////////////////////////////////////////////
975 // NativeWidgetAura, private: 1046 // NativeWidgetAndroid, private:
976 1047
977 bool NativeWidgetAura::IsDocked() const { 1048 bool NativeWidgetAndroid::IsDocked() const {
978 return window_ && 1049 return window_ &&
979 window_->GetProperty(aura::client::kShowStateKey) == 1050 window_->GetProperty(aura::client::kShowStateKey) ==
980 ui::SHOW_STATE_DOCKED; 1051 ui::SHOW_STATE_DOCKED;
981 } 1052 }
982 1053
983 void NativeWidgetAura::SetInitialFocus(ui::WindowShowState show_state) { 1054 void NativeWidgetAndroid::SetInitialFocus(ui::WindowShowState show_state) {
984 // The window does not get keyboard messages unless we focus it. 1055 // The window does not get keyboard messages unless we focus it.
985 if (!GetWidget()->SetInitialFocus(show_state)) 1056 if (!GetWidget()->SetInitialFocus(show_state))
986 window_->Focus(); 1057 window_->Focus();
987 } 1058 }
988 1059
989 ////////////////////////////////////////////////////////////////////////////////
990 // Widget, public:
991
992 namespace {
993 #if defined(OS_WIN) || (defined(USE_X11) && !defined(OS_CHROMEOS))
994 void CloseWindow(aura::Window* window) {
995 if (window) {
996 Widget* widget = Widget::GetWidgetForNativeView(window);
997 if (widget && widget->is_secondary_widget())
998 // To avoid the delay in shutdown caused by using Close which may wait
999 // for animations, use CloseNow. Because this is only used on secondary
1000 // widgets it seems relatively safe to skip the extra processing of
1001 // Close.
1002 widget->CloseNow();
1003 }
1004 }
1005 #endif
1006
1007 #if defined(OS_WIN)
1008 BOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam) {
1009 aura::Window* root_window =
1010 DesktopWindowTreeHostWin::GetContentWindowForHWND(hwnd);
1011 CloseWindow(root_window);
1012 return TRUE;
1013 }
1014 #endif
1015 } // namespace
1016
1017 // static
1018 void Widget::CloseAllSecondaryWidgets() {
1019 #if defined(OS_WIN)
1020 EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, 0);
1021 #endif
1022
1023 #if defined(USE_X11) && !defined(OS_CHROMEOS)
1024 DesktopWindowTreeHostX11::CleanUpWindowList(CloseWindow);
1025 #endif
1026 }
1027
1028 bool Widget::ConvertRect(const Widget* source,
1029 const Widget* target,
1030 gfx::Rect* rect) {
1031 return false;
1032 }
1033
1034 namespace internal {
1035
1036 ////////////////////////////////////////////////////////////////////////////////
1037 // internal::NativeWidgetPrivate, public:
1038
1039 // static
1040 NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget(
1041 internal::NativeWidgetDelegate* delegate) {
1042 return new NativeWidgetAura(delegate);
1043 }
1044
1045 // static
1046 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView(
1047 gfx::NativeView native_view) {
1048 // Cast must match type supplied to RegisterNativeWidgetForWindow().
1049 return reinterpret_cast<NativeWidgetPrivate*>(native_view->user_data());
1050 }
1051
1052 // static
1053 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow(
1054 gfx::NativeWindow native_window) {
1055 // Cast must match type supplied to RegisterNativeWidgetForWindow().
1056 return reinterpret_cast<NativeWidgetPrivate*>(native_window->user_data());
1057 }
1058
1059 // static
1060 NativeWidgetPrivate* NativeWidgetPrivate::GetTopLevelNativeWidget(
1061 gfx::NativeView native_view) {
1062 aura::Window* window = native_view;
1063 NativeWidgetPrivate* top_level_native_widget = NULL;
1064 while (window) {
1065 NativeWidgetPrivate* native_widget = GetNativeWidgetForNativeView(window);
1066 if (native_widget)
1067 top_level_native_widget = native_widget;
1068 window = window->parent();
1069 }
1070 return top_level_native_widget;
1071 }
1072
1073 // static
1074 void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view,
1075 Widget::Widgets* children) {
1076 {
1077 // Code expects widget for |native_view| to be added to |children|.
1078 NativeWidgetPrivate* native_widget = static_cast<NativeWidgetPrivate*>(
1079 GetNativeWidgetForNativeView(native_view));
1080 if (native_widget && native_widget->GetWidget())
1081 children->insert(native_widget->GetWidget());
1082 }
1083
1084 const aura::Window::Windows& child_windows = native_view->children();
1085 for (aura::Window::Windows::const_iterator i = child_windows.begin();
1086 i != child_windows.end(); ++i) {
1087 GetAllChildWidgets((*i), children);
1088 }
1089 }
1090
1091 // static
1092 void NativeWidgetPrivate::GetAllOwnedWidgets(gfx::NativeView native_view,
1093 Widget::Widgets* owned) {
1094 // Add all owned widgets.
1095 for (aura::Window* transient_child : wm::GetTransientChildren(native_view)) {
1096 NativeWidgetPrivate* native_widget = static_cast<NativeWidgetPrivate*>(
1097 GetNativeWidgetForNativeView(transient_child));
1098 if (native_widget && native_widget->GetWidget())
1099 owned->insert(native_widget->GetWidget());
1100 GetAllOwnedWidgets(transient_child, owned);
1101 }
1102
1103 // Add all child windows.
1104 for (aura::Window* child : native_view->children())
1105 GetAllChildWidgets(child, owned);
1106 }
1107
1108 // static
1109 void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view,
1110 gfx::NativeView new_parent) {
1111 DCHECK(native_view != new_parent);
1112
1113 gfx::NativeView previous_parent = native_view->parent();
1114 if (previous_parent == new_parent)
1115 return;
1116
1117 Widget::Widgets widgets;
1118 GetAllChildWidgets(native_view, &widgets);
1119
1120 // First notify all the widgets that they are being disassociated
1121 // from their previous parent.
1122 for (Widget::Widgets::iterator it = widgets.begin();
1123 it != widgets.end(); ++it) {
1124 (*it)->NotifyNativeViewHierarchyWillChange();
1125 }
1126
1127 if (new_parent) {
1128 new_parent->AddChild(native_view);
1129 } else {
1130 // The following looks weird, but it's the equivalent of what aura has
1131 // always done. (The previous behaviour of aura::Window::SetParent() used
1132 // NULL as a special value that meant ask the WindowTreeClient where things
1133 // should go.)
1134 //
1135 // This probably isn't strictly correct, but its an invariant that a Window
1136 // in use will be attached to a RootWindow, so we can't just call
1137 // RemoveChild here. The only possible thing that could assign a RootWindow
1138 // in this case is the stacking client of the current RootWindow. This
1139 // matches our previous behaviour; the global stacking client would almost
1140 // always reattach the window to the same RootWindow.
1141 aura::Window* root_window = native_view->GetRootWindow();
1142 aura::client::ParentWindowWithContext(
1143 native_view, root_window, root_window->GetBoundsInScreen());
1144 }
1145
1146 // And now, notify them that they have a brand new parent.
1147 for (Widget::Widgets::iterator it = widgets.begin();
1148 it != widgets.end(); ++it) {
1149 (*it)->NotifyNativeViewHierarchyChanged();
1150 }
1151 }
1152
1153 // static
1154 bool NativeWidgetPrivate::IsMouseButtonDown() {
1155 return aura::Env::GetInstance()->IsMouseButtonDown();
1156 }
1157
1158 // static
1159 gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() {
1160 #if defined(OS_WIN)
1161 NONCLIENTMETRICS_XP ncm;
1162 base::win::GetNonClientMetrics(&ncm);
1163 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont));
1164 base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont)));
1165 return gfx::FontList(gfx::Font(caption_font));
1166 #else
1167 return gfx::FontList();
1168 #endif
1169 }
1170
1171 } // namespace internal
1172 } // namespace views 1060 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/android/native_widget_android.h ('k') | ui/views/widget/native_widget_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698