1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/views/widget/widget.h"
7 #include "base/debug/trace_event.h"
8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "ui/base/cursor/cursor.h"
12 #include "ui/base/default_theme_provider.h"
13 #include "ui/base/hit_test.h"
14 #include "ui/base/l10n/l10n_font_util.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/compositor/compositor.h"
17 #include "ui/compositor/layer.h"
18 #include "ui/events/event.h"
19 #include "ui/gfx/image/image_skia.h"
20 #include "ui/gfx/screen.h"
21 #include "ui/views/controls/menu/menu_controller.h"
22 #include "ui/views/focus/focus_manager.h"
23 #include "ui/views/focus/focus_manager_factory.h"
24 #include "ui/views/focus/view_storage.h"
25 #include "ui/views/focus/widget_focus_manager.h"
26 #include "ui/views/ime/input_method.h"
27 #include "ui/views/views_delegate.h"
28 #include "ui/views/widget/native_widget_private.h"
29 #include "ui/views/widget/root_view.h"
30 #include "ui/views/widget/tooltip_manager.h"
31 #include "ui/views/widget/widget_delegate.h"
32 #include "ui/views/widget/widget_deletion_observer.h"
33 #include "ui/views/widget/widget_observer.h"
34 #include "ui/views/widget/widget_removals_observer.h"
35 #include "ui/views/window/custom_frame_view.h"
36 #include "ui/views/window/dialog_delegate.h"
42 // If |view| has a layer the layer is added to |layers|. Else this recurses
43 // through the children. This is used to build a list of the layers created by
44 // views that are direct children of the Widgets layer.
45 void BuildRootLayers(View* view, std::vector<ui::Layer*>* layers) {
47 layers->push_back(view->layer());
49 for (int i = 0; i < view->child_count(); ++i)
50 BuildRootLayers(view->child_at(i), layers);
54 // Create a native widget implementation.
55 // First, use the supplied one if non-NULL.
56 // Finally, make a default one.
57 NativeWidget* CreateNativeWidget(NativeWidget* native_widget,
58 internal::NativeWidgetDelegate* delegate) {
61 internal::NativeWidgetPrivate::CreateNativeWidget(delegate);
68 // A default implementation of WidgetDelegate, used by Widget when no
69 // WidgetDelegate is supplied.
70 class DefaultWidgetDelegate : public WidgetDelegate {
72 explicit DefaultWidgetDelegate(Widget* widget) : widget_(widget) {
74 virtual ~DefaultWidgetDelegate() {}
76 // Overridden from WidgetDelegate:
77 virtual void DeleteDelegate() OVERRIDE {
80 virtual Widget* GetWidget() OVERRIDE {
83 virtual const Widget* GetWidget() const OVERRIDE {
86 virtual bool ShouldAdvanceFocusToTopLevelWidget() const OVERRIDE {
87 // In most situations where a Widget is used without a delegate the Widget
88 // is used as a container, so that we want focus to advance to the top-level
89 // widget. A good example of this is the find bar.
96 DISALLOW_COPY_AND_ASSIGN(DefaultWidgetDelegate);
99 ////////////////////////////////////////////////////////////////////////////////
100 // Widget, InitParams:
102 Widget::InitParams::InitParams()
106 opacity(INFER_OPACITY),
108 activatable(ACTIVATABLE_DEFAULT),
110 visible_on_all_workspaces(false),
111 ownership(NATIVE_WIDGET_OWNS_WIDGET),
112 mirror_origin_in_rtl(false),
113 shadow_type(SHADOW_TYPE_DEFAULT),
114 remove_standard_frame(false),
115 use_system_default_icon(false),
116 show_state(ui::SHOW_STATE_DEFAULT),
117 double_buffer(false),
120 desktop_window_tree_host(NULL),
121 layer_type(aura::WINDOW_LAYER_TEXTURED),
123 force_show_in_taskbar(false),
127 Widget::InitParams::InitParams(Type type)
131 opacity(INFER_OPACITY),
133 activatable(ACTIVATABLE_DEFAULT),
134 keep_on_top(type == TYPE_MENU || type == TYPE_DRAG),
135 visible_on_all_workspaces(false),
136 ownership(NATIVE_WIDGET_OWNS_WIDGET),
137 mirror_origin_in_rtl(false),
138 shadow_type(SHADOW_TYPE_DEFAULT),
139 remove_standard_frame(false),
140 use_system_default_icon(false),
141 show_state(ui::SHOW_STATE_DEFAULT),
142 double_buffer(false),
145 desktop_window_tree_host(NULL),
146 layer_type(aura::WINDOW_LAYER_TEXTURED),
148 force_show_in_taskbar(false),
152 Widget::InitParams::~InitParams() {
155 ////////////////////////////////////////////////////////////////////////////////
159 : native_widget_(NULL),
160 widget_delegate_(NULL),
161 non_client_view_(NULL),
163 ownership_(InitParams::NATIVE_WIDGET_OWNS_WIDGET),
164 is_secondary_widget_(true),
165 frame_type_(FRAME_TYPE_DEFAULT),
166 disable_inactive_rendering_(false),
167 widget_closed_(false),
168 saved_show_state_(ui::SHOW_STATE_DEFAULT),
169 focus_on_creation_(true),
170 is_top_level_(false),
171 native_widget_initialized_(false),
172 native_widget_destroyed_(false),
173 is_mouse_button_pressed_(false),
174 is_touch_down_(false),
175 last_mouse_event_was_move_(false),
176 auto_release_capture_(true),
177 root_layers_dirty_(false),
178 movement_disabled_(false),
179 observer_manager_(this) {
184 if (ownership_ == InitParams::WIDGET_OWNS_NATIVE_WIDGET) {
185 delete native_widget_;
187 DCHECK(native_widget_destroyed_)
188 << "Destroying a widget with a live native widget. "
189 << "Widget probably should use WIDGET_OWNS_NATIVE_WIDGET ownership.";
194 Widget* Widget::CreateWindow(WidgetDelegate* delegate) {
195 return CreateWindowWithBounds(delegate, gfx::Rect());
199 Widget* Widget::CreateWindowWithBounds(WidgetDelegate* delegate,
200 const gfx::Rect& bounds) {
201 Widget* widget = new Widget;
202 Widget::InitParams params;
203 params.bounds = bounds;
204 params.delegate = delegate;
205 widget->Init(params);
210 Widget* Widget::CreateWindowWithParent(WidgetDelegate* delegate,
211 gfx::NativeView parent) {
212 return CreateWindowWithParentAndBounds(delegate, parent, gfx::Rect());
216 Widget* Widget::CreateWindowWithParentAndBounds(WidgetDelegate* delegate,
217 gfx::NativeView parent,
218 const gfx::Rect& bounds) {
219 Widget* widget = new Widget;
220 Widget::InitParams params;
221 params.delegate = delegate;
222 params.parent = parent;
223 params.bounds = bounds;
224 widget->Init(params);
229 Widget* Widget::CreateWindowWithContext(WidgetDelegate* delegate,
230 gfx::NativeView context) {
231 return CreateWindowWithContextAndBounds(delegate, context, gfx::Rect());
235 Widget* Widget::CreateWindowWithContextAndBounds(WidgetDelegate* delegate,
236 gfx::NativeView context,
237 const gfx::Rect& bounds) {
238 Widget* widget = new Widget;
239 Widget::InitParams params;
240 params.delegate = delegate;
241 params.context = context;
242 params.bounds = bounds;
243 widget->Init(params);
248 Widget* Widget::GetWidgetForNativeView(gfx::NativeView native_view) {
249 internal::NativeWidgetPrivate* native_widget =
250 internal::NativeWidgetPrivate::GetNativeWidgetForNativeView(native_view);
251 return native_widget ? native_widget->GetWidget() : NULL;
255 Widget* Widget::GetWidgetForNativeWindow(gfx::NativeWindow native_window) {
256 internal::NativeWidgetPrivate* native_widget =
257 internal::NativeWidgetPrivate::GetNativeWidgetForNativeWindow(
259 return native_widget ? native_widget->GetWidget() : NULL;
263 Widget* Widget::GetTopLevelWidgetForNativeView(gfx::NativeView native_view) {
264 internal::NativeWidgetPrivate* native_widget =
265 internal::NativeWidgetPrivate::GetTopLevelNativeWidget(native_view);
266 return native_widget ? native_widget->GetWidget() : NULL;
271 void Widget::GetAllChildWidgets(gfx::NativeView native_view,
273 internal::NativeWidgetPrivate::GetAllChildWidgets(native_view, children);
277 void Widget::GetAllOwnedWidgets(gfx::NativeView native_view,
279 internal::NativeWidgetPrivate::GetAllOwnedWidgets(native_view, owned);
283 void Widget::ReparentNativeView(gfx::NativeView native_view,
284 gfx::NativeView new_parent) {
285 internal::NativeWidgetPrivate::ReparentNativeView(native_view, new_parent);
289 int Widget::GetLocalizedContentsWidth(int col_resource_id) {
290 return ui::GetLocalizedContentsWidthForFont(col_resource_id,
291 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
295 int Widget::GetLocalizedContentsHeight(int row_resource_id) {
296 return ui::GetLocalizedContentsHeightForFont(row_resource_id,
297 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
301 gfx::Size Widget::GetLocalizedContentsSize(int col_resource_id,
302 int row_resource_id) {
303 return gfx::Size(GetLocalizedContentsWidth(col_resource_id),
304 GetLocalizedContentsHeight(row_resource_id));
308 bool Widget::RequiresNonClientView(InitParams::Type type) {
309 return type == InitParams::TYPE_WINDOW ||
310 type == InitParams::TYPE_PANEL ||
311 type == InitParams::TYPE_BUBBLE;
314 void Widget::Init(const InitParams& in_params) {
315 TRACE_EVENT0("views", "Widget::Init");
316 InitParams params = in_params;
318 params.child |= (params.type == InitParams::TYPE_CONTROL);
319 is_top_level_ = !params.child;
321 if (params.opacity == views::Widget::InitParams::INFER_OPACITY &&
322 params.type != views::Widget::InitParams::TYPE_WINDOW &&
323 params.type != views::Widget::InitParams::TYPE_PANEL)
324 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW;
326 if (ViewsDelegate::views_delegate)
327 ViewsDelegate::views_delegate->OnBeforeWidgetInit(¶ms, this);
329 if (params.opacity == views::Widget::InitParams::INFER_OPACITY)
330 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW;
332 bool can_activate = false;
333 if (params.activatable != InitParams::ACTIVATABLE_DEFAULT) {
334 can_activate = (params.activatable == InitParams::ACTIVATABLE_YES);
335 } else if (params.type != InitParams::TYPE_CONTROL &&
336 params.type != InitParams::TYPE_POPUP &&
337 params.type != InitParams::TYPE_MENU &&
338 params.type != InitParams::TYPE_TOOLTIP &&
339 params.type != InitParams::TYPE_DRAG) {
341 params.activatable = InitParams::ACTIVATABLE_YES;
343 can_activate = false;
344 params.activatable = InitParams::ACTIVATABLE_NO;
347 widget_delegate_ = params.delegate ?
348 params.delegate : new DefaultWidgetDelegate(this);
349 widget_delegate_->set_can_activate(can_activate);
351 ownership_ = params.ownership;
352 native_widget_ = CreateNativeWidget(params.native_widget, this)->
353 AsNativeWidgetPrivate();
354 root_view_.reset(CreateRootView());
355 default_theme_provider_.reset(new ui::DefaultThemeProvider);
356 if (params.type == InitParams::TYPE_MENU) {
357 is_mouse_button_pressed_ =
358 internal::NativeWidgetPrivate::IsMouseButtonDown();
360 native_widget_->InitNativeWidget(params);
361 if (RequiresNonClientView(params.type)) {
362 non_client_view_ = new NonClientView;
363 non_client_view_->SetFrameView(CreateNonClientFrameView());
364 // Create the ClientView, add it to the NonClientView and add the
365 // NonClientView to the RootView. This will cause everything to be parented.
366 non_client_view_->set_client_view(widget_delegate_->CreateClientView(this));
367 non_client_view_->SetOverlayView(widget_delegate_->CreateOverlayView());
368 SetContentsView(non_client_view_);
369 // Initialize the window's title before setting the window's initial bounds;
370 // the frame view's preferred height may depend on the presence of a title.
372 non_client_view_->ResetWindowControls();
373 SetInitialBounds(params.bounds);
374 if (params.show_state == ui::SHOW_STATE_MAXIMIZED)
376 else if (params.show_state == ui::SHOW_STATE_MINIMIZED)
378 } else if (params.delegate) {
379 SetContentsView(params.delegate->GetContentsView());
380 SetInitialBoundsForFramelessWindow(params.bounds);
382 // This must come after SetContentsView() or it might not be able to find
383 // the correct NativeTheme (on Linux). See http://crbug.com/384492
384 observer_manager_.Add(GetNativeTheme());
385 native_widget_initialized_ = true;
388 // Unconverted methods (see header) --------------------------------------------
390 gfx::NativeView Widget::GetNativeView() const {
391 return native_widget_->GetNativeView();
394 gfx::NativeWindow Widget::GetNativeWindow() const {
395 return native_widget_->GetNativeWindow();
398 void Widget::AddObserver(WidgetObserver* observer) {
399 observers_.AddObserver(observer);
402 void Widget::RemoveObserver(WidgetObserver* observer) {
403 observers_.RemoveObserver(observer);
406 bool Widget::HasObserver(WidgetObserver* observer) {
407 return observers_.HasObserver(observer);
410 void Widget::AddRemovalsObserver(WidgetRemovalsObserver* observer) {
411 removals_observers_.AddObserver(observer);
414 void Widget::RemoveRemovalsObserver(WidgetRemovalsObserver* observer) {
415 removals_observers_.RemoveObserver(observer);
418 bool Widget::HasRemovalsObserver(WidgetRemovalsObserver* observer) {
419 return removals_observers_.HasObserver(observer);
422 bool Widget::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) const {
426 void Widget::ViewHierarchyChanged(
427 const View::ViewHierarchyChangedDetails& details) {
428 if (!details.is_add) {
429 if (details.child == dragged_view_)
430 dragged_view_ = NULL;
431 FocusManager* focus_manager = GetFocusManager();
433 focus_manager->ViewRemoved(details.child);
434 ViewStorage::GetInstance()->ViewRemoved(details.child);
435 native_widget_->ViewRemoved(details.child);
439 void Widget::NotifyNativeViewHierarchyWillChange() {
440 FocusManager* focus_manager = GetFocusManager();
441 // We are being removed from a window hierarchy. Treat this as
442 // the root_view_ being removed.
444 focus_manager->ViewRemoved(root_view_.get());
447 void Widget::NotifyNativeViewHierarchyChanged() {
448 root_view_->NotifyNativeViewHierarchyChanged();
451 void Widget::NotifyWillRemoveView(View* view) {
452 FOR_EACH_OBSERVER(WidgetRemovalsObserver,
454 OnWillRemoveView(this, view));
457 // Converted methods (see header) ----------------------------------------------
459 Widget* Widget::GetTopLevelWidget() {
460 return const_cast<Widget*>(
461 static_cast<const Widget*>(this)->GetTopLevelWidget());
464 const Widget* Widget::GetTopLevelWidget() const {
465 // GetTopLevelNativeWidget doesn't work during destruction because
466 // property is gone after gobject gets deleted. Short circuit here
467 // for toplevel so that InputMethod can remove itself from
469 return is_top_level() ? this : native_widget_->GetTopLevelWidget();
472 void Widget::SetContentsView(View* view) {
473 // Do not SetContentsView() again if it is already set to the same view.
474 if (view == GetContentsView())
476 root_view_->SetContentsView(view);
477 if (non_client_view_ != view) {
478 // |non_client_view_| can only be non-NULL here if RequiresNonClientView()
479 // was true when the widget was initialized. Creating widgets with non
480 // client views and then setting the contents view can cause subtle
481 // problems on Windows, where the native widget thinks there is still a
482 // |non_client_view_|. If you get this error, either use a different type
483 // when initializing the widget, or don't call SetContentsView().
484 DCHECK(!non_client_view_);
485 non_client_view_ = NULL;
489 View* Widget::GetContentsView() {
490 return root_view_->GetContentsView();
493 gfx::Rect Widget::GetWindowBoundsInScreen() const {
494 return native_widget_->GetWindowBoundsInScreen();
497 gfx::Rect Widget::GetClientAreaBoundsInScreen() const {
498 return native_widget_->GetClientAreaBoundsInScreen();
501 gfx::Rect Widget::GetRestoredBounds() const {
502 return native_widget_->GetRestoredBounds();
505 void Widget::SetBounds(const gfx::Rect& bounds) {
506 native_widget_->SetBounds(bounds);
509 void Widget::SetSize(const gfx::Size& size) {
510 native_widget_->SetSize(size);
513 void Widget::CenterWindow(const gfx::Size& size) {
514 native_widget_->CenterWindow(size);
517 void Widget::SetBoundsConstrained(const gfx::Rect& bounds) {
518 gfx::Rect work_area =
519 gfx::Screen::GetScreenFor(GetNativeView())->GetDisplayNearestPoint(
520 bounds.origin()).work_area();
521 if (work_area.IsEmpty()) {
524 // Inset the work area slightly.
525 work_area.Inset(10, 10, 10, 10);
526 work_area.AdjustToFit(bounds);
527 SetBounds(work_area);
531 void Widget::SetVisibilityChangedAnimationsEnabled(bool value) {
532 native_widget_->SetVisibilityChangedAnimationsEnabled(value);
535 Widget::MoveLoopResult Widget::RunMoveLoop(
536 const gfx::Vector2d& drag_offset,
537 MoveLoopSource source,
538 MoveLoopEscapeBehavior escape_behavior) {
539 return native_widget_->RunMoveLoop(drag_offset, source, escape_behavior);
542 void Widget::EndMoveLoop() {
543 native_widget_->EndMoveLoop();
546 void Widget::StackAboveWidget(Widget* widget) {
547 native_widget_->StackAbove(widget->GetNativeView());
550 void Widget::StackAbove(gfx::NativeView native_view) {
551 native_widget_->StackAbove(native_view);
554 void Widget::StackAtTop() {
555 native_widget_->StackAtTop();
558 void Widget::StackBelow(gfx::NativeView native_view) {
559 native_widget_->StackBelow(native_view);
562 void Widget::SetShape(gfx::NativeRegion shape) {
563 native_widget_->SetShape(shape);
566 void Widget::Close() {
567 if (widget_closed_) {
568 // It appears we can hit this code path if you close a modal dialog then
569 // close the last browser before the destructor is hit, which triggers
570 // invoking Close again.
574 bool can_close = true;
575 if (non_client_view_)
576 can_close = non_client_view_->CanClose();
578 SaveWindowPlacement();
580 // During tear-down the top-level focus manager becomes unavailable to
581 // GTK tabbed panes and their children, so normal deregistration via
582 // |FormManager::ViewRemoved()| calls are fouled. We clear focus here
583 // to avoid these redundant steps and to avoid accessing deleted views
584 // that may have been in focus.
585 if (is_top_level() && focus_manager_.get())
586 focus_manager_->SetFocusedView(NULL);
588 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetClosing(this));
589 native_widget_->Close();
590 widget_closed_ = true;
594 void Widget::CloseNow() {
595 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetClosing(this));
596 native_widget_->CloseNow();
599 bool Widget::IsClosed() const {
600 return widget_closed_;
603 void Widget::Show() {
604 TRACE_EVENT0("views", "Widget::Show");
605 if (non_client_view_) {
606 // While initializing, the kiosk mode will go to full screen before the
607 // widget gets shown. In that case we stay in full screen mode, regardless
608 // of the |saved_show_state_| member.
609 if (saved_show_state_ == ui::SHOW_STATE_MAXIMIZED &&
610 !initial_restored_bounds_.IsEmpty() &&
612 native_widget_->ShowMaximizedWithBounds(initial_restored_bounds_);
614 native_widget_->ShowWithWindowState(
615 IsFullscreen() ? ui::SHOW_STATE_FULLSCREEN : saved_show_state_);
617 // |saved_show_state_| only applies the first time the window is shown.
618 // If we don't reset the value the window may be shown maximized every time
619 // it is subsequently shown after being hidden.
620 saved_show_state_ = ui::SHOW_STATE_NORMAL;
623 ? native_widget_->Show()
624 : native_widget_->ShowWithWindowState(ui::SHOW_STATE_INACTIVE);
628 void Widget::Hide() {
629 native_widget_->Hide();
632 void Widget::ShowInactive() {
633 // If this gets called with saved_show_state_ == ui::SHOW_STATE_MAXIMIZED,
634 // call SetBounds()with the restored bounds to set the correct size. This
635 // normally should not happen, but if it does we should avoid showing unsized
637 if (saved_show_state_ == ui::SHOW_STATE_MAXIMIZED &&
638 !initial_restored_bounds_.IsEmpty()) {
639 SetBounds(initial_restored_bounds_);
640 saved_show_state_ = ui::SHOW_STATE_NORMAL;
642 native_widget_->ShowWithWindowState(ui::SHOW_STATE_INACTIVE);
645 void Widget::Activate() {
646 native_widget_->Activate();
649 void Widget::Deactivate() {
650 native_widget_->Deactivate();
653 bool Widget::IsActive() const {
654 return native_widget_->IsActive();
657 void Widget::DisableInactiveRendering() {
658 SetInactiveRenderingDisabled(true);
661 void Widget::SetAlwaysOnTop(bool on_top) {
662 native_widget_->SetAlwaysOnTop(on_top);
665 bool Widget::IsAlwaysOnTop() const {
666 return native_widget_->IsAlwaysOnTop();
669 void Widget::SetVisibleOnAllWorkspaces(bool always_visible) {
670 native_widget_->SetVisibleOnAllWorkspaces(always_visible);
673 void Widget::Maximize() {
674 native_widget_->Maximize();
677 void Widget::Minimize() {
678 native_widget_->Minimize();
681 void Widget::Restore() {
682 native_widget_->Restore();
685 bool Widget::IsMaximized() const {
686 return native_widget_->IsMaximized();
689 bool Widget::IsMinimized() const {
690 return native_widget_->IsMinimized();
693 void Widget::SetFullscreen(bool fullscreen) {
694 if (IsFullscreen() == fullscreen)
697 native_widget_->SetFullscreen(fullscreen);
699 if (non_client_view_)
700 non_client_view_->Layout();
703 bool Widget::IsFullscreen() const {
704 return native_widget_->IsFullscreen();
707 void Widget::SetOpacity(unsigned char opacity) {
708 native_widget_->SetOpacity(opacity);
711 void Widget::SetUseDragFrame(bool use_drag_frame) {
712 native_widget_->SetUseDragFrame(use_drag_frame);
715 void Widget::FlashFrame(bool flash) {
716 native_widget_->FlashFrame(flash);
719 View* Widget::GetRootView() {
720 return root_view_.get();
723 const View* Widget::GetRootView() const {
724 return root_view_.get();
727 bool Widget::IsVisible() const {
728 return native_widget_->IsVisible();
731 ui::ThemeProvider* Widget::GetThemeProvider() const {
732 const Widget* root_widget = GetTopLevelWidget();
733 if (root_widget && root_widget != this) {
734 // Attempt to get the theme provider, and fall back to the default theme
735 // provider if not found.
736 ui::ThemeProvider* provider = root_widget->GetThemeProvider();
740 provider = root_widget->default_theme_provider_.get();
744 return default_theme_provider_.get();
747 const ui::NativeTheme* Widget::GetNativeTheme() const {
748 return native_widget_->GetNativeTheme();
751 FocusManager* Widget::GetFocusManager() {
752 Widget* toplevel_widget = GetTopLevelWidget();
753 return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL;
756 const FocusManager* Widget::GetFocusManager() const {
757 const Widget* toplevel_widget = GetTopLevelWidget();
758 return toplevel_widget ? toplevel_widget->focus_manager_.get() : NULL;
761 InputMethod* Widget::GetInputMethod() {
762 return const_cast<InputMethod*>(
763 const_cast<const Widget*>(this)->GetInputMethod());
766 const InputMethod* Widget::GetInputMethod() const {
767 if (is_top_level()) {
768 if (!input_method_.get())
769 input_method_ = const_cast<Widget*>(this)->CreateInputMethod().Pass();
770 return input_method_.get();
772 const Widget* toplevel = GetTopLevelWidget();
773 // If GetTopLevelWidget() returns itself which is not toplevel,
774 // the widget is detached from toplevel widget.
775 // TODO(oshima): Fix GetTopLevelWidget() to return NULL
776 // if there is no toplevel. We probably need to add GetTopMostWidget()
777 // to replace some use cases.
778 return (toplevel && toplevel != this) ? toplevel->GetInputMethod() : NULL;
782 ui::InputMethod* Widget::GetHostInputMethod() {
783 return native_widget_private()->GetHostInputMethod();
786 void Widget::RunShellDrag(View* view,
787 const ui::OSExchangeData& data,
788 const gfx::Point& location,
790 ui::DragDropTypes::DragEventSource source) {
791 dragged_view_ = view;
792 native_widget_->RunShellDrag(view, data, location, operation, source);
793 // If the view is removed during the drag operation, dragged_view_ is set to
795 if (view && dragged_view_ == view) {
796 dragged_view_ = NULL;
801 void Widget::SchedulePaintInRect(const gfx::Rect& rect) {
802 native_widget_->SchedulePaintInRect(rect);
805 void Widget::SetCursor(gfx::NativeCursor cursor) {
806 native_widget_->SetCursor(cursor);
809 bool Widget::IsMouseEventsEnabled() const {
810 return native_widget_->IsMouseEventsEnabled();
813 void Widget::SetNativeWindowProperty(const char* name, void* value) {
814 native_widget_->SetNativeWindowProperty(name, value);
817 void* Widget::GetNativeWindowProperty(const char* name) const {
818 return native_widget_->GetNativeWindowProperty(name);
821 void Widget::UpdateWindowTitle() {
822 if (!non_client_view_)
825 // Update the native frame's text. We do this regardless of whether or not
826 // the native frame is being used, since this also updates the taskbar, etc.
827 base::string16 window_title = widget_delegate_->GetWindowTitle();
828 base::i18n::AdjustStringForLocaleDirection(&window_title);
829 if (!native_widget_->SetWindowTitle(window_title))
831 non_client_view_->UpdateWindowTitle();
833 // If the non-client view is rendering its own title, it'll need to relayout
834 // now and to get a paint update later on.
835 non_client_view_->Layout();
838 void Widget::UpdateWindowIcon() {
839 if (non_client_view_)
840 non_client_view_->UpdateWindowIcon();
841 native_widget_->SetWindowIcons(widget_delegate_->GetWindowIcon(),
842 widget_delegate_->GetWindowAppIcon());
845 FocusTraversable* Widget::GetFocusTraversable() {
846 return static_cast<internal::RootView*>(root_view_.get());
849 void Widget::ThemeChanged() {
850 root_view_->ThemeChanged();
853 void Widget::LocaleChanged() {
854 root_view_->LocaleChanged();
857 void Widget::SetFocusTraversableParent(FocusTraversable* parent) {
858 root_view_->SetFocusTraversableParent(parent);
861 void Widget::SetFocusTraversableParentView(View* parent_view) {
862 root_view_->SetFocusTraversableParentView(parent_view);
865 void Widget::ClearNativeFocus() {
866 native_widget_->ClearNativeFocus();
869 NonClientFrameView* Widget::CreateNonClientFrameView() {
870 NonClientFrameView* frame_view =
871 widget_delegate_->CreateNonClientFrameView(this);
873 frame_view = native_widget_->CreateNonClientFrameView();
874 if (!frame_view && ViewsDelegate::views_delegate) {
876 ViewsDelegate::views_delegate->CreateDefaultNonClientFrameView(this);
881 CustomFrameView* custom_frame_view = new CustomFrameView;
882 custom_frame_view->Init(this);
883 return custom_frame_view;
886 bool Widget::ShouldUseNativeFrame() const {
887 if (frame_type_ != FRAME_TYPE_DEFAULT)
888 return frame_type_ == FRAME_TYPE_FORCE_NATIVE;
889 return native_widget_->ShouldUseNativeFrame();
892 bool Widget::ShouldWindowContentsBeTransparent() const {
893 return native_widget_->ShouldWindowContentsBeTransparent();
896 void Widget::DebugToggleFrameType() {
897 if (frame_type_ == FRAME_TYPE_DEFAULT) {
898 frame_type_ = ShouldUseNativeFrame() ? FRAME_TYPE_FORCE_CUSTOM :
899 FRAME_TYPE_FORCE_NATIVE;
901 frame_type_ = frame_type_ == FRAME_TYPE_FORCE_CUSTOM ?
902 FRAME_TYPE_FORCE_NATIVE : FRAME_TYPE_FORCE_CUSTOM;
907 void Widget::FrameTypeChanged() {
908 native_widget_->FrameTypeChanged();
911 const ui::Compositor* Widget::GetCompositor() const {
912 return native_widget_->GetCompositor();
915 ui::Compositor* Widget::GetCompositor() {
916 return native_widget_->GetCompositor();
919 ui::Layer* Widget::GetLayer() {
920 return native_widget_->GetLayer();
923 void Widget::ReorderNativeViews() {
924 native_widget_->ReorderNativeViews();
927 void Widget::UpdateRootLayers() {
928 // Calculate the layers requires traversing the tree, and since nearly any
929 // mutation of the tree can trigger this call we delay until absolutely
931 root_layers_dirty_ = true;
934 const NativeWidget* Widget::native_widget() const {
935 return native_widget_;
938 NativeWidget* Widget::native_widget() {
939 return native_widget_;
942 void Widget::SetCapture(View* view) {
943 if (internal::NativeWidgetPrivate::IsMouseButtonDown())
944 is_mouse_button_pressed_ = true;
945 if (internal::NativeWidgetPrivate::IsTouchDown())
946 is_touch_down_ = true;
947 root_view_->SetMouseHandler(view);
948 if (!native_widget_->HasCapture())
949 native_widget_->SetCapture();
952 void Widget::ReleaseCapture() {
953 if (native_widget_->HasCapture())
954 native_widget_->ReleaseCapture();
957 bool Widget::HasCapture() {
958 return native_widget_->HasCapture();
961 TooltipManager* Widget::GetTooltipManager() {
962 return native_widget_->GetTooltipManager();
965 const TooltipManager* Widget::GetTooltipManager() const {
966 return native_widget_->GetTooltipManager();
969 gfx::Rect Widget::GetWorkAreaBoundsInScreen() const {
970 return native_widget_->GetWorkAreaBoundsInScreen();
973 void Widget::SynthesizeMouseMoveEvent() {
974 last_mouse_event_was_move_ = false;
975 ui::MouseEvent mouse_event(ui::ET_MOUSE_MOVED,
976 last_mouse_event_position_,
977 last_mouse_event_position_,
978 ui::EF_IS_SYNTHESIZED, 0);
979 root_view_->OnMouseMoved(mouse_event);
982 void Widget::OnRootViewLayout() {
983 native_widget_->OnRootViewLayout();
986 void Widget::OnOwnerClosing() {
989 ////////////////////////////////////////////////////////////////////////////////
990 // Widget, NativeWidgetDelegate implementation:
992 bool Widget::IsModal() const {
993 return widget_delegate_->GetModalType() != ui::MODAL_TYPE_NONE;
996 bool Widget::IsDialogBox() const {
997 return !!widget_delegate_->AsDialogDelegate();
1000 bool Widget::CanActivate() const {
1001 return widget_delegate_->CanActivate();
1004 bool Widget::IsInactiveRenderingDisabled() const {
1005 return disable_inactive_rendering_;
1008 void Widget::EnableInactiveRendering() {
1009 SetInactiveRenderingDisabled(false);
1012 void Widget::OnNativeWidgetActivationChanged(bool active) {
1013 // On windows we may end up here before we've completed initialization (from
1014 // an WM_NCACTIVATE). If that happens the WidgetDelegate likely doesn't know
1015 // the Widget and will crash attempting to access it.
1016 if (!active && native_widget_initialized_)
1017 SaveWindowPlacement();
1019 FOR_EACH_OBSERVER(WidgetObserver, observers_,
1020 OnWidgetActivationChanged(this, active));
1022 // During window creation, the widget gets focused without activation, and in
1023 // that case, the focus manager cannot set the appropriate text input client
1024 // because the widget is not active. Thus we have to notify the focus manager
1025 // not only when the focus changes but also when the widget gets activated.
1026 // See crbug.com/377479 for details.
1027 views::FocusManager* focus_manager = GetFocusManager();
1028 if (focus_manager) {
1030 focus_manager->FocusTextInputClient(focus_manager->GetFocusedView());
1032 focus_manager->BlurTextInputClient(focus_manager->GetFocusedView());
1035 if (IsVisible() && non_client_view())
1036 non_client_view()->frame_view()->SchedulePaint();
1039 void Widget::OnNativeFocus(gfx::NativeView old_focused_view) {
1040 WidgetFocusManager::GetInstance()->OnWidgetFocusEvent(old_focused_view,
1044 void Widget::OnNativeBlur(gfx::NativeView new_focused_view) {
1045 WidgetFocusManager::GetInstance()->OnWidgetFocusEvent(GetNativeView(),
1049 void Widget::OnNativeWidgetVisibilityChanging(bool visible) {
1050 FOR_EACH_OBSERVER(WidgetObserver, observers_,
1051 OnWidgetVisibilityChanging(this, visible));
1054 void Widget::OnNativeWidgetVisibilityChanged(bool visible) {
1055 View* root = GetRootView();
1057 root->PropagateVisibilityNotifications(root, visible);
1058 FOR_EACH_OBSERVER(WidgetObserver, observers_,
1059 OnWidgetVisibilityChanged(this, visible));
1060 if (GetCompositor() && root && root->layer())
1061 root->layer()->SetVisible(visible);
1064 void Widget::OnNativeWidgetCreated(bool desktop_widget) {
1066 focus_manager_.reset(FocusManagerFactory::Create(this, desktop_widget));
1068 native_widget_->InitModalType(widget_delegate_->GetModalType());
1070 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetCreated(this));
1073 void Widget::OnNativeWidgetDestroying() {
1074 // Tell the focus manager (if any) that root_view is being removed
1075 // in case that the focused view is under this root view.
1076 if (GetFocusManager())
1077 GetFocusManager()->ViewRemoved(root_view_.get());
1078 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetDestroying(this));
1079 if (non_client_view_)
1080 non_client_view_->WindowClosing();
1081 widget_delegate_->WindowClosing();
1084 void Widget::OnNativeWidgetDestroyed() {
1085 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetDestroyed(this));
1086 widget_delegate_->DeleteDelegate();
1087 widget_delegate_ = NULL;
1088 native_widget_destroyed_ = true;
1091 gfx::Size Widget::GetMinimumSize() const {
1092 return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size();
1095 gfx::Size Widget::GetMaximumSize() const {
1096 return non_client_view_ ? non_client_view_->GetMaximumSize() : gfx::Size();
1099 void Widget::OnNativeWidgetMove() {
1100 widget_delegate_->OnWidgetMove();
1101 View* root = GetRootView();
1102 if (root && root->GetFocusManager()) {
1103 View* focused_view = root->GetFocusManager()->GetFocusedView();
1104 if (focused_view && focused_view->GetInputMethod())
1105 focused_view->GetInputMethod()->OnCaretBoundsChanged(focused_view);
1107 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged(
1109 GetWindowBoundsInScreen()));
1112 void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) {
1113 View* root = GetRootView();
1115 root->SetSize(new_size);
1116 if (root->GetFocusManager()) {
1117 View* focused_view = GetRootView()->GetFocusManager()->GetFocusedView();
1118 if (focused_view && focused_view->GetInputMethod())
1119 focused_view->GetInputMethod()->OnCaretBoundsChanged(focused_view);
1122 // Size changed notifications can fire prior to full initialization
1123 // i.e. during session restore. Avoid saving session state during these
1124 // startup procedures.
1125 if (native_widget_initialized_)
1126 SaveWindowPlacement();
1128 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged(
1130 GetWindowBoundsInScreen()));
1133 void Widget::OnNativeWidgetBeginUserBoundsChange() {
1134 widget_delegate_->OnWindowBeginUserBoundsChange();
1137 void Widget::OnNativeWidgetEndUserBoundsChange() {
1138 widget_delegate_->OnWindowEndUserBoundsChange();
1141 bool Widget::HasFocusManager() const {
1142 return !!focus_manager_.get();
1145 bool Widget::OnNativeWidgetPaintAccelerated(const gfx::Rect& dirty_region) {
1146 ui::Compositor* compositor = GetCompositor();
1150 compositor->ScheduleRedrawRect(dirty_region);
1154 void Widget::OnNativeWidgetPaint(gfx::Canvas* canvas) {
1155 // On Linux Aura, we can get here during Init() because of the
1156 // SetInitialBounds call.
1157 if (native_widget_initialized_)
1158 GetRootView()->Paint(canvas, CullSet());
1161 int Widget::GetNonClientComponent(const gfx::Point& point) {
1162 int component = non_client_view_ ?
1163 non_client_view_->NonClientHitTest(point) :
1166 if (movement_disabled_ && (component == HTCAPTION || component == HTSYSMENU))
1172 void Widget::OnKeyEvent(ui::KeyEvent* event) {
1173 SendEventToProcessor(event);
1176 // TODO(tdanderson): We should not be calling the OnMouse*() functions on
1177 // RootView from anywhere in Widget. Use
1178 // SendEventToProcessor() instead. See crbug.com/348087.
1179 void Widget::OnMouseEvent(ui::MouseEvent* event) {
1180 View* root_view = GetRootView();
1181 switch (event->type()) {
1182 case ui::ET_MOUSE_PRESSED: {
1183 last_mouse_event_was_move_ = false;
1185 // We may get deleted by the time we return from OnMousePressed. So we
1186 // use an observer to make sure we are still alive.
1187 WidgetDeletionObserver widget_deletion_observer(this);
1189 // Make sure we're still visible before we attempt capture as the mouse
1190 // press processing may have made the window hide (as happens with menus).
1192 // It is possible for a View to show a context menu on mouse-press. Since
1193 // the menu does a capture and starts a nested message-loop, the release
1194 // would go to the menu. The next click (i.e. both mouse-press and release
1195 // events) also go to the menu. The menu (and the nested message-loop)
1196 // gets closed after this second release event. The code then resumes from
1197 // here. So make sure that the mouse-button is still down before doing a
1199 if (root_view && root_view->OnMousePressed(*event) &&
1200 widget_deletion_observer.IsWidgetAlive() && IsVisible() &&
1201 internal::NativeWidgetPrivate::IsMouseButtonDown()) {
1202 is_mouse_button_pressed_ = true;
1203 if (!native_widget_->HasCapture())
1204 native_widget_->SetCapture();
1205 event->SetHandled();
1210 case ui::ET_MOUSE_RELEASED:
1211 last_mouse_event_was_move_ = false;
1212 is_mouse_button_pressed_ = false;
1213 // Release capture first, to avoid confusion if OnMouseReleased blocks.
1214 if (auto_release_capture_ && native_widget_->HasCapture())
1215 native_widget_->ReleaseCapture();
1217 root_view->OnMouseReleased(*event);
1218 if ((event->flags() & ui::EF_IS_NON_CLIENT) == 0)
1219 event->SetHandled();
1222 case ui::ET_MOUSE_MOVED:
1223 case ui::ET_MOUSE_DRAGGED:
1224 if (native_widget_->HasCapture() && is_mouse_button_pressed_) {
1225 last_mouse_event_was_move_ = false;
1227 root_view->OnMouseDragged(*event);
1228 } else if (!last_mouse_event_was_move_ ||
1229 last_mouse_event_position_ != event->location()) {
1230 last_mouse_event_position_ = event->location();
1231 last_mouse_event_was_move_ = true;
1233 root_view->OnMouseMoved(*event);
1237 case ui::ET_MOUSE_EXITED:
1238 last_mouse_event_was_move_ = false;
1240 root_view->OnMouseExited(*event);
1243 case ui::ET_MOUSEWHEEL:
1244 if (root_view && root_view->OnMouseWheel(
1245 static_cast<const ui::MouseWheelEvent&>(*event)))
1246 event->SetHandled();
1254 void Widget::OnMouseCaptureLost() {
1255 if (is_mouse_button_pressed_ || is_touch_down_) {
1256 View* root_view = GetRootView();
1258 root_view->OnMouseCaptureLost();
1260 is_touch_down_ = false;
1261 is_mouse_button_pressed_ = false;
1264 void Widget::OnScrollEvent(ui::ScrollEvent* event) {
1265 ui::ScrollEvent event_copy(*event);
1266 SendEventToProcessor(&event_copy);
1268 // Convert unhandled ui::ET_SCROLL events into ui::ET_MOUSEWHEEL events.
1269 if (!event_copy.handled() && event_copy.type() == ui::ET_SCROLL) {
1270 ui::MouseWheelEvent wheel(*event);
1271 OnMouseEvent(&wheel);
1275 void Widget::OnGestureEvent(ui::GestureEvent* event) {
1276 switch (event->type()) {
1277 case ui::ET_GESTURE_TAP_DOWN:
1278 is_touch_down_ = true;
1279 // We explicitly don't capture here. Not capturing enables multiple
1280 // widgets to get tap events at the same time. Views (such as tab
1281 // dragging) may explicitly capture.
1284 case ui::ET_GESTURE_END:
1285 if (event->details().touch_points() == 1)
1286 is_touch_down_ = false;
1292 SendEventToProcessor(event);
1295 bool Widget::ExecuteCommand(int command_id) {
1296 return widget_delegate_->ExecuteWindowsCommand(command_id);
1299 InputMethod* Widget::GetInputMethodDirect() {
1300 return input_method_.get();
1303 const std::vector<ui::Layer*>& Widget::GetRootLayers() {
1304 if (root_layers_dirty_) {
1305 root_layers_dirty_ = false;
1306 root_layers_.clear();
1307 BuildRootLayers(GetRootView(), &root_layers_);
1309 return root_layers_;
1312 bool Widget::HasHitTestMask() const {
1313 return widget_delegate_->WidgetHasHitTestMask();
1316 void Widget::GetHitTestMask(gfx::Path* mask) const {
1318 widget_delegate_->GetWidgetHitTestMask(mask);
1321 Widget* Widget::AsWidget() {
1325 const Widget* Widget::AsWidget() const {
1329 bool Widget::SetInitialFocus(ui::WindowShowState show_state) {
1330 View* v = widget_delegate_->GetInitiallyFocusedView();
1331 if (!focus_on_creation_ || show_state == ui::SHOW_STATE_INACTIVE ||
1332 show_state == ui::SHOW_STATE_MINIMIZED) {
1333 // If not focusing the window now, tell the focus manager which view to
1334 // focus when the window is restored.
1336 focus_manager_->SetStoredFocusView(v);
1344 ////////////////////////////////////////////////////////////////////////////////
1345 // Widget, ui::EventSource implementation:
1346 ui::EventProcessor* Widget::GetEventProcessor() {
1347 return root_view_.get();
1350 ////////////////////////////////////////////////////////////////////////////////
1351 // Widget, FocusTraversable implementation:
1353 FocusSearch* Widget::GetFocusSearch() {
1354 return root_view_->GetFocusSearch();
1357 FocusTraversable* Widget::GetFocusTraversableParent() {
1358 // We are a proxy to the root view, so we should be bypassed when traversing
1359 // up and as a result this should not be called.
1364 View* Widget::GetFocusTraversableParentView() {
1365 // We are a proxy to the root view, so we should be bypassed when traversing
1366 // up and as a result this should not be called.
1371 ////////////////////////////////////////////////////////////////////////////////
1372 // Widget, ui::NativeThemeObserver implementation:
1374 void Widget::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) {
1375 DCHECK(observer_manager_.IsObserving(observed_theme));
1377 ui::NativeTheme* current_native_theme = GetNativeTheme();
1378 if (!observer_manager_.IsObserving(current_native_theme)) {
1379 observer_manager_.RemoveAll();
1380 observer_manager_.Add(current_native_theme);
1383 root_view_->PropagateNativeThemeChanged(current_native_theme);
1386 ////////////////////////////////////////////////////////////////////////////////
1387 // Widget, protected:
1389 internal::RootView* Widget::CreateRootView() {
1390 return new internal::RootView(this);
1393 void Widget::DestroyRootView() {
1394 non_client_view_ = NULL;
1396 // Input method has to be destroyed before focus manager.
1397 input_method_.reset();
1400 ////////////////////////////////////////////////////////////////////////////////
1403 void Widget::SetInactiveRenderingDisabled(bool value) {
1404 if (value == disable_inactive_rendering_)
1407 disable_inactive_rendering_ = value;
1408 if (non_client_view_)
1409 non_client_view_->SetInactiveRenderingDisabled(value);
1412 void Widget::SaveWindowPlacement() {
1413 // The window delegate does the actual saving for us. It seems like (judging
1414 // by go/crash) that in some circumstances we can end up here after
1415 // WM_DESTROY, at which point the window delegate is likely gone. So just
1417 if (!widget_delegate_)
1420 ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL;
1422 native_widget_->GetWindowPlacement(&bounds, &show_state);
1423 widget_delegate_->SaveWindowPlacement(bounds, show_state);
1426 void Widget::SetInitialBounds(const gfx::Rect& bounds) {
1427 if (!non_client_view_)
1430 gfx::Rect saved_bounds;
1431 if (GetSavedWindowPlacement(&saved_bounds, &saved_show_state_)) {
1432 if (saved_show_state_ == ui::SHOW_STATE_MAXIMIZED) {
1433 // If we're going to maximize, wait until Show is invoked to set the
1434 // bounds. That way we avoid a noticeable resize.
1435 initial_restored_bounds_ = saved_bounds;
1436 } else if (!saved_bounds.IsEmpty()) {
1437 // If the saved bounds are valid, use them.
1438 SetBounds(saved_bounds);
1441 if (bounds.IsEmpty()) {
1442 // No initial bounds supplied, so size the window to its content and
1443 // center over its parent.
1444 native_widget_->CenterWindow(non_client_view_->GetPreferredSize());
1446 // Use the supplied initial bounds.
1447 SetBoundsConstrained(bounds);
1452 void Widget::SetInitialBoundsForFramelessWindow(const gfx::Rect& bounds) {
1453 if (bounds.IsEmpty()) {
1454 View* contents_view = GetContentsView();
1455 DCHECK(contents_view);
1456 // No initial bounds supplied, so size the window to its content and
1457 // center over its parent if preferred size is provided.
1458 gfx::Size size = contents_view->GetPreferredSize();
1459 if (!size.IsEmpty())
1460 native_widget_->CenterWindow(size);
1462 // Use the supplied initial bounds.
1463 SetBoundsConstrained(bounds);
1467 bool Widget::GetSavedWindowPlacement(gfx::Rect* bounds,
1468 ui::WindowShowState* show_state) {
1469 // First we obtain the window's saved show-style and store it. We need to do
1470 // this here, rather than in Show() because by the time Show() is called,
1471 // the window's size will have been reset (below) and the saved maximized
1472 // state will have been lost. Sadly there's no way to tell on Windows when
1473 // a window is restored from maximized state, so we can't more accurately
1474 // track maximized state independently of sizing information.
1476 // Restore the window's placement from the controller.
1477 if (widget_delegate_->GetSavedWindowPlacement(this, bounds, show_state)) {
1478 if (!widget_delegate_->ShouldRestoreWindowSize()) {
1479 bounds->set_size(non_client_view_->GetPreferredSize());
1481 gfx::Size minimum_size = GetMinimumSize();
1482 // Make sure the bounds are at least the minimum size.
1483 if (bounds->width() < minimum_size.width())
1484 bounds->set_width(minimum_size.width());
1486 if (bounds->height() < minimum_size.height())
1487 bounds->set_height(minimum_size.height());
1494 scoped_ptr<InputMethod> Widget::CreateInputMethod() {
1495 scoped_ptr<InputMethod> input_method(native_widget_->CreateInputMethod());
1496 if (input_method.get())
1497 input_method->Init(this);
1498 return input_method.Pass();
1501 void Widget::ReplaceInputMethod(InputMethod* input_method) {
1502 input_method_.reset(input_method);
1503 input_method->SetDelegate(native_widget_->GetInputMethodDelegate());
1504 input_method->Init(this);
1507 namespace internal {
1509 ////////////////////////////////////////////////////////////////////////////////
1510 // internal::NativeWidgetPrivate, NativeWidget implementation:
1512 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() {
1516 } // namespace internal
1517 } // namespace views