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

Side by Side Diff: ui/views/widget/native_widget_aura.cc

Issue 8547015: Revert 110949 - views: Move widget/ directory to ui/views. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/widget/native_widget_aura.h ('k') | ui/views/widget/native_widget_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/views/widget/native_widget_aura.h"
6
7 #include "base/bind.h"
8 #include "base/string_util.h"
9 #include "ui/aura/client/aura_constants.h"
10 #include "ui/aura/client/drag_drop_client.h"
11 #include "ui/aura/desktop.h"
12 #include "ui/aura/desktop_observer.h"
13 #include "ui/aura/event.h"
14 #include "ui/aura/window.h"
15 #include "ui/aura/window_types.h"
16 #include "ui/base/dragdrop/os_exchange_data.h"
17 #include "ui/base/ui_base_types.h"
18 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/compositor/layer.h"
20 #include "ui/gfx/font.h"
21 #include "ui/gfx/screen.h"
22 #include "ui/views/widget/drop_helper.h"
23 #include "ui/views/widget/native_widget_delegate.h"
24 #include "ui/views/widget/tooltip_manager_views.h"
25
26 #if defined(OS_WIN)
27 #include "base/win/scoped_gdi_object.h"
28 #include "base/win/win_util.h"
29 #include "ui/base/l10n/l10n_util_win.h"
30 #endif
31
32 #if defined(HAVE_IBUS)
33 #include "ui/views/ime/input_method_ibus.h"
34 #else
35 #include "ui/views/ime/mock_input_method.h"
36 #endif
37
38 namespace views {
39
40 namespace {
41
42 aura::WindowType GetAuraWindowTypeForWidgetType(Widget::InitParams::Type type) {
43 switch (type) {
44 case Widget::InitParams::TYPE_WINDOW:
45 return aura::WINDOW_TYPE_NORMAL;
46 case Widget::InitParams::TYPE_WINDOW_FRAMELESS:
47 case Widget::InitParams::TYPE_CONTROL:
48 case Widget::InitParams::TYPE_POPUP:
49 case Widget::InitParams::TYPE_BUBBLE:
50 return aura::WINDOW_TYPE_POPUP;
51 case Widget::InitParams::TYPE_MENU:
52 return aura::WINDOW_TYPE_MENU;
53 case Widget::InitParams::TYPE_TOOLTIP:
54 return aura::WINDOW_TYPE_TOOLTIP;
55 default:
56 NOTREACHED() << "Unhandled widget type " << type;
57 return aura::WINDOW_TYPE_UNKNOWN;
58 }
59 }
60
61 } // namespace
62
63 // Used when SetInactiveRenderingDisabled() is invoked to track when active
64 // status changes in such a way that we should enable inactive rendering.
65 class NativeWidgetAura::DesktopObserverImpl : public aura::DesktopObserver {
66 public:
67 explicit DesktopObserverImpl(NativeWidgetAura* host)
68 : host_(host) {
69 aura::Desktop::GetInstance()->AddObserver(this);
70 }
71
72 virtual ~DesktopObserverImpl() {
73 aura::Desktop::GetInstance()->RemoveObserver(this);
74 }
75
76 // DesktopObserver overrides:
77 virtual void OnActiveWindowChanged(aura::Window* active) OVERRIDE {
78 if (!active || (active != host_->window_ &&
79 active->transient_parent() != host_->window_)) {
80 host_->delegate_->EnableInactiveRendering();
81 }
82 }
83
84 private:
85 NativeWidgetAura* host_;
86
87 DISALLOW_COPY_AND_ASSIGN(DesktopObserverImpl);
88 };
89
90 ////////////////////////////////////////////////////////////////////////////////
91 // NativeWidgetAura, public:
92
93 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate)
94 : delegate_(delegate),
95 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))),
96 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
97 ALLOW_THIS_IN_INITIALIZER_LIST(close_widget_factory_(this)),
98 can_activate_(true),
99 cursor_(gfx::kNullCursor) {
100 }
101
102 NativeWidgetAura::~NativeWidgetAura() {
103 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
104 delete delegate_;
105 else
106 CloseNow();
107 }
108
109 // static
110 gfx::Font NativeWidgetAura::GetWindowTitleFont() {
111 #if defined(OS_WIN)
112 NONCLIENTMETRICS ncm;
113 base::win::GetNonClientMetrics(&ncm);
114 l10n_util::AdjustUIFont(&(ncm.lfCaptionFont));
115 base::win::ScopedHFONT caption_font(CreateFontIndirect(&(ncm.lfCaptionFont)));
116 return gfx::Font(caption_font);
117 #else
118 return gfx::Font();
119 #endif
120 }
121
122 ////////////////////////////////////////////////////////////////////////////////
123 // NativeWidgetAura, internal::NativeWidgetPrivate implementation:
124
125 void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) {
126 ownership_ = params.ownership;
127 window_->set_user_data(this);
128 Widget::InitParams::Type window_type =
129 params.child ? Widget::InitParams::TYPE_CONTROL : params.type;
130 window_->SetType(GetAuraWindowTypeForWidgetType(window_type));
131 window_->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_NORMAL);
132 window_->Init(params.create_texture_for_layer ?
133 ui::Layer::LAYER_HAS_TEXTURE :
134 ui::Layer::LAYER_HAS_NO_TEXTURE);
135 if (window_type == Widget::InitParams::TYPE_CONTROL)
136 window_->Show();
137
138 window_->layer()->SetFillsBoundsOpaquely(!params.transparent);
139 delegate_->OnNativeWidgetCreated();
140 window_->SetBounds(params.bounds);
141 if (window_type == Widget::InitParams::TYPE_CONTROL) {
142 window_->SetParent(params.GetParent());
143 } else {
144 // Set up the transient child before the window is added. This way the
145 // LayoutManager knows the window has a transient parent.
146 gfx::NativeView parent = params.GetParent();
147 if (parent)
148 parent->AddTransientChild(window_);
149 // SetAlwaysOnTop before SetParent so that always-on-top container is used.
150 SetAlwaysOnTop(params.keep_on_top);
151 window_->SetParent(NULL);
152 }
153 window_->set_ignore_events(!params.accept_events);
154 // TODO(beng): do this some other way.
155 delegate_->OnNativeWidgetSizeChanged(params.bounds.size());
156 can_activate_ = params.can_activate;
157 DCHECK(GetWidget()->GetRootView());
158 if (params.type != Widget::InitParams::TYPE_TOOLTIP && !params.child) {
159 views::TooltipManagerViews* manager = new views::TooltipManagerViews(
160 GetWidget()->GetRootView());
161 tooltip_manager_.reset(manager);
162 }
163 drop_helper_.reset(new DropHelper(GetWidget()->GetRootView()));
164 if (params.type != Widget::InitParams::TYPE_TOOLTIP &&
165 params.type != Widget::InitParams::TYPE_POPUP) {
166 window_->SetProperty(aura::kDragDropDelegateKey,
167 static_cast<aura::WindowDragDropDelegate*>(this));
168 }
169 }
170
171 NonClientFrameView* NativeWidgetAura::CreateNonClientFrameView() {
172 return NULL;
173 }
174
175 void NativeWidgetAura::UpdateFrameAfterFrameChange() {
176 // We don't support changing the frame type.
177 NOTREACHED();
178 }
179
180 bool NativeWidgetAura::ShouldUseNativeFrame() const {
181 // There is only one frame type for aura.
182 return false;
183 }
184
185 void NativeWidgetAura::FrameTypeChanged() {
186 // This is called when the Theme has changed; forward the event to the root
187 // widget.
188 GetWidget()->ThemeChanged();
189 GetWidget()->GetRootView()->SchedulePaint();
190 }
191
192 Widget* NativeWidgetAura::GetWidget() {
193 return delegate_->AsWidget();
194 }
195
196 const Widget* NativeWidgetAura::GetWidget() const {
197 return delegate_->AsWidget();
198 }
199
200 gfx::NativeView NativeWidgetAura::GetNativeView() const {
201 return window_;
202 }
203
204 gfx::NativeWindow NativeWidgetAura::GetNativeWindow() const {
205 return window_;
206 }
207
208 Widget* NativeWidgetAura::GetTopLevelWidget() {
209 NativeWidgetPrivate* native_widget = GetTopLevelNativeWidget(GetNativeView());
210 return native_widget ? native_widget->GetWidget() : NULL;
211 }
212
213 const ui::Compositor* NativeWidgetAura::GetCompositor() const {
214 return window_->layer()->GetCompositor();
215 }
216
217 ui::Compositor* NativeWidgetAura::GetCompositor() {
218 return window_->layer()->GetCompositor();
219 }
220
221 void NativeWidgetAura::CalculateOffsetToAncestorWithLayer(
222 gfx::Point* offset,
223 ui::Layer** layer_parent) {
224 if (layer_parent)
225 *layer_parent = window_->layer();
226 }
227
228 void NativeWidgetAura::ReorderLayers() {
229 }
230
231 void NativeWidgetAura::ViewRemoved(View* view) {
232 // DropTarget stuff. Most likely http://crbug.com/97845
233 //NOTIMPLEMENTED();
234 }
235
236 void NativeWidgetAura::SetNativeWindowProperty(const char* name, void* value) {
237 if (window_)
238 window_->SetProperty(name, value);
239 }
240
241 void* NativeWidgetAura::GetNativeWindowProperty(const char* name) const {
242 return window_ ? window_->GetProperty(name) : NULL;
243 }
244
245 TooltipManager* NativeWidgetAura::GetTooltipManager() const {
246 return tooltip_manager_.get();
247 }
248
249 bool NativeWidgetAura::IsScreenReaderActive() const {
250 // http://crbug.com/102570
251 //NOTIMPLEMENTED();
252 return false;
253 }
254
255 void NativeWidgetAura::SendNativeAccessibilityEvent(
256 View* view,
257 ui::AccessibilityTypes::Event event_type) {
258 // http://crbug.com/102570
259 //NOTIMPLEMENTED();
260 }
261
262 void NativeWidgetAura::SetMouseCapture() {
263 window_->SetCapture();
264 }
265
266 void NativeWidgetAura::ReleaseMouseCapture() {
267 window_->ReleaseCapture();
268 }
269
270 bool NativeWidgetAura::HasMouseCapture() const {
271 return window_->HasCapture();
272 }
273
274 InputMethod* NativeWidgetAura::CreateInputMethod() {
275 #if defined(HAVE_IBUS)
276 InputMethod* input_method = new InputMethodIBus(this);
277 #else
278 InputMethod* input_method = new MockInputMethod(this);
279 #endif
280 input_method->Init(GetWidget());
281 return input_method;
282 }
283
284 void NativeWidgetAura::CenterWindow(const gfx::Size& size) {
285 const gfx::Rect parent_bounds = window_->parent()->bounds();
286 window_->SetBounds(gfx::Rect((parent_bounds.width() - size.width())/2,
287 (parent_bounds.height() - size.height())/2,
288 size.width(),
289 size.height()));
290 }
291
292 void NativeWidgetAura::GetWindowPlacement(
293 gfx::Rect* bounds,
294 ui::WindowShowState* show_state) const {
295 *bounds = window_->GetTargetBounds();
296 *show_state = static_cast<ui::WindowShowState>(
297 window_->GetIntProperty(aura::kShowStateKey));
298 }
299
300 void NativeWidgetAura::SetWindowTitle(const string16& title) {
301 window_->set_title(title);
302 }
303
304 void NativeWidgetAura::SetWindowIcons(const SkBitmap& window_icon,
305 const SkBitmap& app_icon) {
306 // Aura doesn't have window icons.
307 }
308
309 void NativeWidgetAura::SetAccessibleName(const string16& name) {
310 // http://crbug.com/102570
311 //NOTIMPLEMENTED();
312 }
313
314 void NativeWidgetAura::SetAccessibleRole(ui::AccessibilityTypes::Role role) {
315 // http://crbug.com/102570
316 //NOTIMPLEMENTED();
317 }
318
319 void NativeWidgetAura::SetAccessibleState(ui::AccessibilityTypes::State state) {
320 // http://crbug.com/102570
321 //NOTIMPLEMENTED();
322 }
323
324 void NativeWidgetAura::BecomeModal() {
325 window_->SetIntProperty(aura::kModalKey, 1);
326 }
327
328 gfx::Rect NativeWidgetAura::GetWindowScreenBounds() const {
329 return window_->GetScreenBounds();
330 }
331
332 gfx::Rect NativeWidgetAura::GetClientAreaScreenBounds() const {
333 // In Aura, the entire window is the client area.
334 return window_->GetScreenBounds();
335 }
336
337 gfx::Rect NativeWidgetAura::GetRestoredBounds() const {
338 gfx::Rect* restore_bounds = reinterpret_cast<gfx::Rect*>(
339 window_->GetProperty(aura::kRestoreBoundsKey));
340 return restore_bounds ? *restore_bounds : window_->bounds();
341 }
342
343 void NativeWidgetAura::SetBounds(const gfx::Rect& bounds) {
344 window_->SetBounds(bounds);
345 }
346
347 void NativeWidgetAura::SetSize(const gfx::Size& size) {
348 window_->SetBounds(gfx::Rect(window_->bounds().origin(), size));
349 }
350
351 void NativeWidgetAura::MoveAbove(gfx::NativeView native_view) {
352 if (window_->parent() && window_->parent() == native_view->parent())
353 window_->parent()->MoveChildAbove(window_, native_view);
354 }
355
356 void NativeWidgetAura::MoveToTop() {
357 window_->parent()->MoveChildToFront(window_);
358 }
359
360 void NativeWidgetAura::SetShape(gfx::NativeRegion region) {
361 // No need for this.
362 }
363
364 void NativeWidgetAura::Close() {
365 // |window_| may already be deleted by parent window. This can happen
366 // when this widget is child widget or has transient parent
367 // and ownership is WIDGET_OWNS_NATIVE_WIDGET.
368 DCHECK(window_ ||
369 ownership_ == Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET);
370 if (window_)
371 Hide();
372
373 window_->SetIntProperty(aura::kModalKey, 0);
374
375 if (!close_widget_factory_.HasWeakPtrs()) {
376 MessageLoop::current()->PostTask(
377 FROM_HERE,
378 base::Bind(&NativeWidgetAura::CloseNow,
379 close_widget_factory_.GetWeakPtr()));
380 }
381 }
382
383 void NativeWidgetAura::CloseNow() {
384 delete window_;
385 }
386
387 void NativeWidgetAura::EnableClose(bool enable) {
388 // http://crbug.com/102581
389 NOTIMPLEMENTED();
390 }
391
392 void NativeWidgetAura::Show() {
393 ShowWithWindowState(ui::SHOW_STATE_INACTIVE);
394 }
395
396 void NativeWidgetAura::Hide() {
397 window_->Hide();
398 }
399
400 void NativeWidgetAura::ShowMaximizedWithBounds(
401 const gfx::Rect& restored_bounds) {
402 window_->SetBounds(restored_bounds);
403 ShowWithWindowState(ui::SHOW_STATE_MAXIMIZED);
404 }
405
406 void NativeWidgetAura::ShowWithWindowState(ui::WindowShowState state) {
407 if (state == ui::SHOW_STATE_MAXIMIZED ||
408 state == ui::SHOW_STATE_FULLSCREEN) {
409 window_->SetIntProperty(aura::kShowStateKey, state);
410 }
411 window_->Show();
412 if (can_activate_ && (state != ui::SHOW_STATE_INACTIVE ||
413 !GetWidget()->SetInitialFocus())) {
414 window_->Activate();
415 }
416 }
417
418 bool NativeWidgetAura::IsVisible() const {
419 return window_->IsVisible();
420 }
421
422 void NativeWidgetAura::Activate() {
423 window_->Activate();
424 }
425
426 void NativeWidgetAura::Deactivate() {
427 window_->Deactivate();
428 }
429
430 bool NativeWidgetAura::IsActive() const {
431 return aura::Desktop::GetInstance()->active_window() == window_;
432 }
433
434 void NativeWidgetAura::SetAlwaysOnTop(bool on_top) {
435 window_->SetIntProperty(aura::kAlwaysOnTopKey, on_top);
436 }
437
438 void NativeWidgetAura::Maximize() {
439 window_->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
440 }
441
442 void NativeWidgetAura::Minimize() {
443 // No minimized window for aura. crbug.com/104571.
444 NOTREACHED();
445 }
446
447 bool NativeWidgetAura::IsMaximized() const {
448 return window_->GetIntProperty(aura::kShowStateKey) ==
449 ui::SHOW_STATE_MAXIMIZED;
450 }
451
452 bool NativeWidgetAura::IsMinimized() const {
453 return window_->GetIntProperty(aura::kShowStateKey) ==
454 ui::SHOW_STATE_MINIMIZED;
455 }
456
457 void NativeWidgetAura::Restore() {
458 window_->SetIntProperty(aura::kShowStateKey, ui::SHOW_STATE_NORMAL);
459 }
460
461 void NativeWidgetAura::SetFullscreen(bool fullscreen) {
462 window_->SetIntProperty(
463 aura::kShowStateKey,
464 fullscreen ? ui::SHOW_STATE_FULLSCREEN : ui::SHOW_STATE_NORMAL);
465 }
466
467 bool NativeWidgetAura::IsFullscreen() const {
468 return window_->GetIntProperty(aura::kShowStateKey) ==
469 ui::SHOW_STATE_FULLSCREEN;
470 }
471
472 void NativeWidgetAura::SetOpacity(unsigned char opacity) {
473 window_->layer()->SetOpacity(opacity / 255.0);
474 }
475
476 void NativeWidgetAura::SetUseDragFrame(bool use_drag_frame) {
477 NOTIMPLEMENTED();
478 }
479
480 bool NativeWidgetAura::IsAccessibleWidget() const {
481 // http://crbug.com/102570
482 //NOTIMPLEMENTED();
483 return false;
484 }
485
486 void NativeWidgetAura::RunShellDrag(View* view,
487 const ui::OSExchangeData& data,
488 int operation) {
489 aura::DragDropClient* client = static_cast<aura::DragDropClient*>(
490 aura::Desktop::GetInstance()->GetProperty(
491 aura::kDesktopDragDropClientKey));
492 if (client)
493 client->StartDragAndDrop(data, operation);
494 }
495
496 void NativeWidgetAura::SchedulePaintInRect(const gfx::Rect& rect) {
497 if (window_)
498 window_->SchedulePaintInRect(rect);
499 }
500
501 void NativeWidgetAura::SetCursor(gfx::NativeCursor cursor) {
502 cursor_ = cursor;
503 aura::Desktop::GetInstance()->SetCursor(cursor);
504 }
505
506 void NativeWidgetAura::ClearNativeFocus() {
507 if (window_ && window_->GetFocusManager())
508 window_->GetFocusManager()->SetFocusedWindow(window_);
509 }
510
511 void NativeWidgetAura::FocusNativeView(gfx::NativeView native_view) {
512 // http://crbug.com/102572
513 NOTIMPLEMENTED();
514 }
515
516 bool NativeWidgetAura::ConvertPointFromAncestor(const Widget* ancestor,
517 gfx::Point* point) const {
518 // http://crbug.com/102573
519 NOTIMPLEMENTED();
520 return false;
521 }
522
523 gfx::Rect NativeWidgetAura::GetWorkAreaBoundsInScreen() const {
524 return gfx::Screen::GetMonitorWorkAreaNearestWindow(GetNativeView());
525 }
526
527 void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) {
528 if (!value)
529 desktop_observer_.reset();
530 else
531 desktop_observer_.reset(new DesktopObserverImpl(this));
532 }
533
534 ////////////////////////////////////////////////////////////////////////////////
535 // NativeWidgetAura, views::InputMethodDelegate implementation:
536
537 void NativeWidgetAura::DispatchKeyEventPostIME(const KeyEvent& key) {
538 if (delegate_->OnKeyEvent(key))
539 return;
540 if (key.type() == ui::ET_KEY_PRESSED && GetWidget()->GetFocusManager())
541 GetWidget()->GetFocusManager()->OnKeyEvent(key);
542 }
543
544 ////////////////////////////////////////////////////////////////////////////////
545 // NativeWidgetAura, aura::WindowDelegate implementation:
546
547 void NativeWidgetAura::OnBoundsChanging(gfx::Rect* new_bounds) {
548 // Enforces a minimum size.
549 const gfx::Size& min_size = delegate_->GetMinimumSize();
550 new_bounds->set_width(std::max(min_size.width(), new_bounds->width()));
551 new_bounds->set_height(std::max(min_size.height(), new_bounds->height()));
552 }
553
554 void NativeWidgetAura::OnBoundsChanged(const gfx::Rect& old_bounds,
555 const gfx::Rect& new_bounds) {
556 if (old_bounds.origin() != new_bounds.origin())
557 GetWidget()->widget_delegate()->OnWidgetMove();
558 if (old_bounds.size() != new_bounds.size())
559 delegate_->OnNativeWidgetSizeChanged(new_bounds.size());
560 }
561
562 void NativeWidgetAura::OnFocus() {
563 Widget* widget = GetWidget();
564 if (widget->is_top_level()) {
565 InputMethod* input_method = widget->GetInputMethod();
566 input_method->OnFocus();
567 // See description of got_initial_focus_in_ for details on this.
568 // TODO(mazda): Investigate this is actually necessary.
569 // widget->GetFocusManager()->RestoreFocusedView();
570 }
571 delegate_->OnNativeFocus(window_);
572 }
573
574 void NativeWidgetAura::OnBlur() {
575 Widget* widget = GetWidget();
576 if (widget->is_top_level()) {
577 InputMethod* input_method = widget->GetInputMethod();
578 input_method->OnBlur();
579 widget->GetFocusManager()->StoreFocusedView();
580 }
581 delegate_->OnNativeBlur(NULL);
582 }
583
584 bool NativeWidgetAura::OnKeyEvent(aura::KeyEvent* event) {
585 // TODO(beng): Need an InputMethodAura to properly handle character events.
586 // Right now, we just skip these.
587 if (event->is_char())
588 return false;
589
590 DCHECK(window_->IsVisible());
591 InputMethod* input_method = GetWidget()->GetInputMethod();
592 DCHECK(input_method);
593 // TODO(oshima): DispatchKeyEvent should return bool?
594 KeyEvent views_event(event);
595 input_method->DispatchKeyEvent(views_event);
596 return true;
597 }
598
599 gfx::NativeCursor NativeWidgetAura::GetCursor(const gfx::Point& point) {
600 return cursor_;
601 }
602
603 int NativeWidgetAura::GetNonClientComponent(const gfx::Point& point) const {
604 return delegate_->GetNonClientComponent(point);
605 }
606
607 bool NativeWidgetAura::OnMouseEvent(aura::MouseEvent* event) {
608 DCHECK(window_->IsVisible());
609 if (event->type() == ui::ET_MOUSEWHEEL) {
610 MouseWheelEvent wheel_event(event);
611 if (tooltip_manager_.get())
612 tooltip_manager_->UpdateForMouseEvent(wheel_event);
613 return delegate_->OnMouseEvent(wheel_event);
614 }
615 MouseEvent mouse_event(event);
616 if (tooltip_manager_.get())
617 tooltip_manager_->UpdateForMouseEvent(mouse_event);
618 return delegate_->OnMouseEvent(mouse_event);
619 }
620
621 ui::TouchStatus NativeWidgetAura::OnTouchEvent(aura::TouchEvent* event) {
622 DCHECK(window_->IsVisible());
623 TouchEvent touch_event(event);
624 return delegate_->OnTouchEvent(touch_event);
625 }
626
627 bool NativeWidgetAura::ShouldActivate(aura::Event* event) {
628 return can_activate_;
629 }
630
631 void NativeWidgetAura::OnActivated() {
632 delegate_->OnNativeWidgetActivationChanged(true);
633 if (IsVisible() && GetWidget()->non_client_view())
634 GetWidget()->non_client_view()->SchedulePaint();
635 }
636
637 void NativeWidgetAura::OnLostActive() {
638 delegate_->OnNativeWidgetActivationChanged(false);
639 if (IsVisible() && GetWidget()->non_client_view())
640 GetWidget()->non_client_view()->SchedulePaint();
641 }
642
643 void NativeWidgetAura::OnCaptureLost() {
644 delegate_->OnMouseCaptureLost();
645 }
646
647 void NativeWidgetAura::OnPaint(gfx::Canvas* canvas) {
648 delegate_->OnNativeWidgetPaint(canvas);
649 }
650
651 void NativeWidgetAura::OnWindowDestroying() {
652 window_->SetProperty(aura::kDragDropDelegateKey, NULL);
653 delegate_->OnNativeWidgetDestroying();
654
655 // If the aura::Window is destroyed, we can no longer show tooltips.
656 tooltip_manager_.reset();
657 }
658
659 void NativeWidgetAura::OnWindowDestroyed() {
660 window_ = NULL;
661 tooltip_manager_.reset();
662 delegate_->OnNativeWidgetDestroyed();
663 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
664 delete this;
665 }
666
667 void NativeWidgetAura::OnWindowVisibilityChanged(bool visible) {
668 delegate_->OnNativeWidgetVisibilityChanged(visible);
669 }
670
671 bool NativeWidgetAura::CanDrop(const aura::DropTargetEvent& event) {
672 DCHECK(drop_helper_.get() != NULL);
673 View* view = drop_helper_->target_view();
674 if (view)
675 return view->CanDrop(event.data());
676 return false;
677 }
678
679 void NativeWidgetAura::OnDragEntered(const aura::DropTargetEvent& event) {
680 DCHECK(drop_helper_.get() != NULL);
681 drop_helper_->OnDragOver(event.data(), event.location(),
682 event.source_operations());
683 }
684
685 int NativeWidgetAura::OnDragUpdated(const aura::DropTargetEvent& event) {
686 DCHECK(drop_helper_.get() != NULL);
687 return drop_helper_->OnDragOver(event.data(), event.location(),
688 event.source_operations());
689 }
690
691 void NativeWidgetAura::OnDragExited() {
692 DCHECK(drop_helper_.get() != NULL);
693 drop_helper_->OnDragExit();
694 }
695
696 int NativeWidgetAura::OnPerformDrop(const aura::DropTargetEvent& event) {
697 DCHECK(drop_helper_.get() != NULL);
698 return drop_helper_->OnDrop(event.data(), event.location(),
699 event.source_operations());
700 }
701
702 ////////////////////////////////////////////////////////////////////////////////
703 // Widget, public:
704
705 // static
706 void Widget::NotifyLocaleChanged() {
707 // http://crbug.com/102574
708 NOTIMPLEMENTED();
709 }
710
711 // static
712 void Widget::CloseAllSecondaryWidgets() {
713 // http://crbug.com/102575
714 NOTIMPLEMENTED();
715 }
716
717 bool Widget::ConvertRect(const Widget* source,
718 const Widget* target,
719 gfx::Rect* rect) {
720 return false;
721 }
722
723 namespace internal {
724
725 ////////////////////////////////////////////////////////////////////////////////
726 // internal::NativeWidgetPrivate, public:
727
728 // static
729 NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget(
730 internal::NativeWidgetDelegate* delegate) {
731 return new NativeWidgetAura(delegate);
732 }
733
734 // static
735 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView(
736 gfx::NativeView native_view) {
737 return reinterpret_cast<NativeWidgetAura*>(native_view->user_data());
738 }
739
740 // static
741 NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow(
742 gfx::NativeWindow native_window) {
743 return reinterpret_cast<NativeWidgetAura*>(native_window->user_data());
744 }
745
746 // static
747 NativeWidgetPrivate* NativeWidgetPrivate::GetTopLevelNativeWidget(
748 gfx::NativeView native_view) {
749 aura::Window* window = native_view;
750 NativeWidgetPrivate* top_level_native_widget = NULL;
751 while (window) {
752 NativeWidgetPrivate* native_widget = GetNativeWidgetForNativeView(window);
753 if (native_widget)
754 top_level_native_widget = native_widget;
755 window = window->parent();
756 }
757 return top_level_native_widget;
758 }
759
760 // static
761 void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view,
762 Widget::Widgets* children) {
763 {
764 // Code expects widget for |native_view| to be added to |children|.
765 NativeWidgetAura* native_widget = static_cast<NativeWidgetAura*>(
766 GetNativeWidgetForNativeView(native_view));
767 if (native_widget->GetWidget())
768 children->insert(native_widget->GetWidget());
769 }
770
771 const aura::Window::Windows& child_windows = native_view->children();
772 for (aura::Window::Windows::const_iterator i = child_windows.begin();
773 i != child_windows.end(); ++i) {
774 NativeWidgetAura* native_widget =
775 static_cast<NativeWidgetAura*>(GetNativeWidgetForNativeView(*i));
776 if (native_widget)
777 children->insert(native_widget->GetWidget());
778 }
779 }
780
781 // static
782 void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view,
783 gfx::NativeView new_parent) {
784 // http://crbug.com/102576
785 NOTIMPLEMENTED();
786 }
787
788 // static
789 bool NativeWidgetPrivate::IsMouseButtonDown() {
790 return aura::Desktop::GetInstance()->IsMouseButtonDown();
791 }
792
793 } // namespace internal
794 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/native_widget_aura.h ('k') | ui/views/widget/native_widget_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698