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 ignore_capture_loss_(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::NativeWindow context) {
231 return CreateWindowWithContextAndBounds(delegate, context, gfx::Rect());
235 Widget* Widget::CreateWindowWithContextAndBounds(WidgetDelegate* delegate,
236 gfx::NativeWindow 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;
793 native_widget_->RunShellDrag(view, data, location, operation, source);
794 // If the view is removed during the drag operation, dragged_view_ is set to
796 if (view && dragged_view_ == view) {
797 dragged_view_ = NULL;
803 void Widget::SchedulePaintInRect(const gfx::Rect& rect) {
804 native_widget_->SchedulePaintInRect(rect);
807 void Widget::SetCursor(gfx::NativeCursor cursor) {
808 native_widget_->SetCursor(cursor);
811 bool Widget::IsMouseEventsEnabled() const {
812 return native_widget_->IsMouseEventsEnabled();
815 void Widget::SetNativeWindowProperty(const char* name, void* value) {
816 native_widget_->SetNativeWindowProperty(name, value);
819 void* Widget::GetNativeWindowProperty(const char* name) const {
820 return native_widget_->GetNativeWindowProperty(name);
823 void Widget::UpdateWindowTitle() {
824 if (!non_client_view_)
827 // Update the native frame's text. We do this regardless of whether or not
828 // the native frame is being used, since this also updates the taskbar, etc.
829 base::string16 window_title = widget_delegate_->GetWindowTitle();
830 base::i18n::AdjustStringForLocaleDirection(&window_title);
831 if (!native_widget_->SetWindowTitle(window_title))
833 non_client_view_->UpdateWindowTitle();
835 // If the non-client view is rendering its own title, it'll need to relayout
836 // now and to get a paint update later on.
837 non_client_view_->Layout();
840 void Widget::UpdateWindowIcon() {
841 if (non_client_view_)
842 non_client_view_->UpdateWindowIcon();
843 native_widget_->SetWindowIcons(widget_delegate_->GetWindowIcon(),
844 widget_delegate_->GetWindowAppIcon());
847 FocusTraversable* Widget::GetFocusTraversable() {
848 return static_cast<internal::RootView*>(root_view_.get());
851 void Widget::ThemeChanged() {
852 root_view_->ThemeChanged();
855 void Widget::LocaleChanged() {
856 root_view_->LocaleChanged();
859 void Widget::SetFocusTraversableParent(FocusTraversable* parent) {
860 root_view_->SetFocusTraversableParent(parent);
863 void Widget::SetFocusTraversableParentView(View* parent_view) {
864 root_view_->SetFocusTraversableParentView(parent_view);
867 void Widget::ClearNativeFocus() {
868 native_widget_->ClearNativeFocus();
871 NonClientFrameView* Widget::CreateNonClientFrameView() {
872 NonClientFrameView* frame_view =
873 widget_delegate_->CreateNonClientFrameView(this);
875 frame_view = native_widget_->CreateNonClientFrameView();
876 if (!frame_view && ViewsDelegate::views_delegate) {
878 ViewsDelegate::views_delegate->CreateDefaultNonClientFrameView(this);
883 CustomFrameView* custom_frame_view = new CustomFrameView;
884 custom_frame_view->Init(this);
885 return custom_frame_view;
888 bool Widget::ShouldUseNativeFrame() const {
889 if (frame_type_ != FRAME_TYPE_DEFAULT)
890 return frame_type_ == FRAME_TYPE_FORCE_NATIVE;
891 return native_widget_->ShouldUseNativeFrame();
894 bool Widget::ShouldWindowContentsBeTransparent() const {
895 return native_widget_->ShouldWindowContentsBeTransparent();
898 void Widget::DebugToggleFrameType() {
899 if (frame_type_ == FRAME_TYPE_DEFAULT) {
900 frame_type_ = ShouldUseNativeFrame() ? FRAME_TYPE_FORCE_CUSTOM :
901 FRAME_TYPE_FORCE_NATIVE;
903 frame_type_ = frame_type_ == FRAME_TYPE_FORCE_CUSTOM ?
904 FRAME_TYPE_FORCE_NATIVE : FRAME_TYPE_FORCE_CUSTOM;
909 void Widget::FrameTypeChanged() {
910 native_widget_->FrameTypeChanged();
913 const ui::Compositor* Widget::GetCompositor() const {
914 return native_widget_->GetCompositor();
917 ui::Compositor* Widget::GetCompositor() {
918 return native_widget_->GetCompositor();
921 ui::Layer* Widget::GetLayer() {
922 return native_widget_->GetLayer();
925 void Widget::ReorderNativeViews() {
926 native_widget_->ReorderNativeViews();
929 void Widget::UpdateRootLayers() {
930 // Calculate the layers requires traversing the tree, and since nearly any
931 // mutation of the tree can trigger this call we delay until absolutely
933 root_layers_dirty_ = true;
936 const NativeWidget* Widget::native_widget() const {
937 return native_widget_;
940 NativeWidget* Widget::native_widget() {
941 return native_widget_;
944 void Widget::SetCapture(View* view) {
945 if (!native_widget_->HasCapture()) {
946 native_widget_->SetCapture();
948 // Early return if setting capture was unsuccessful.
949 if (!native_widget_->HasCapture())
953 if (internal::NativeWidgetPrivate::IsMouseButtonDown())
954 is_mouse_button_pressed_ = true;
955 root_view_->SetMouseHandler(view);
958 void Widget::ReleaseCapture() {
959 if (native_widget_->HasCapture())
960 native_widget_->ReleaseCapture();
963 bool Widget::HasCapture() {
964 return native_widget_->HasCapture();
967 TooltipManager* Widget::GetTooltipManager() {
968 return native_widget_->GetTooltipManager();
971 const TooltipManager* Widget::GetTooltipManager() const {
972 return native_widget_->GetTooltipManager();
975 gfx::Rect Widget::GetWorkAreaBoundsInScreen() const {
976 return native_widget_->GetWorkAreaBoundsInScreen();
979 void Widget::SynthesizeMouseMoveEvent() {
980 last_mouse_event_was_move_ = false;
981 ui::MouseEvent mouse_event(ui::ET_MOUSE_MOVED,
982 last_mouse_event_position_,
983 last_mouse_event_position_,
984 ui::EF_IS_SYNTHESIZED, 0);
985 root_view_->OnMouseMoved(mouse_event);
988 void Widget::OnRootViewLayout() {
989 native_widget_->OnRootViewLayout();
992 bool Widget::IsTranslucentWindowOpacitySupported() const {
993 return native_widget_->IsTranslucentWindowOpacitySupported();
996 void Widget::OnOwnerClosing() {
999 ////////////////////////////////////////////////////////////////////////////////
1000 // Widget, NativeWidgetDelegate implementation:
1002 bool Widget::IsModal() const {
1003 return widget_delegate_->GetModalType() != ui::MODAL_TYPE_NONE;
1006 bool Widget::IsDialogBox() const {
1007 return !!widget_delegate_->AsDialogDelegate();
1010 bool Widget::CanActivate() const {
1011 return widget_delegate_->CanActivate();
1014 bool Widget::IsInactiveRenderingDisabled() const {
1015 return disable_inactive_rendering_;
1018 void Widget::EnableInactiveRendering() {
1019 SetInactiveRenderingDisabled(false);
1022 void Widget::OnNativeWidgetActivationChanged(bool active) {
1023 // On windows we may end up here before we've completed initialization (from
1024 // an WM_NCACTIVATE). If that happens the WidgetDelegate likely doesn't know
1025 // the Widget and will crash attempting to access it.
1026 if (!active && native_widget_initialized_)
1027 SaveWindowPlacement();
1029 FOR_EACH_OBSERVER(WidgetObserver, observers_,
1030 OnWidgetActivationChanged(this, active));
1032 // During window creation, the widget gets focused without activation, and in
1033 // that case, the focus manager cannot set the appropriate text input client
1034 // because the widget is not active. Thus we have to notify the focus manager
1035 // not only when the focus changes but also when the widget gets activated.
1036 // See crbug.com/377479 for details.
1037 views::FocusManager* focus_manager = GetFocusManager();
1038 if (focus_manager) {
1040 focus_manager->FocusTextInputClient(focus_manager->GetFocusedView());
1042 focus_manager->BlurTextInputClient(focus_manager->GetFocusedView());
1045 if (IsVisible() && non_client_view())
1046 non_client_view()->frame_view()->SchedulePaint();
1049 void Widget::OnNativeFocus(gfx::NativeView old_focused_view) {
1050 WidgetFocusManager::GetInstance()->OnWidgetFocusEvent(old_focused_view,
1054 void Widget::OnNativeBlur(gfx::NativeView new_focused_view) {
1055 WidgetFocusManager::GetInstance()->OnWidgetFocusEvent(GetNativeView(),
1059 void Widget::OnNativeWidgetVisibilityChanging(bool visible) {
1060 FOR_EACH_OBSERVER(WidgetObserver, observers_,
1061 OnWidgetVisibilityChanging(this, visible));
1064 void Widget::OnNativeWidgetVisibilityChanged(bool visible) {
1065 View* root = GetRootView();
1067 root->PropagateVisibilityNotifications(root, visible);
1068 FOR_EACH_OBSERVER(WidgetObserver, observers_,
1069 OnWidgetVisibilityChanged(this, visible));
1070 if (GetCompositor() && root && root->layer())
1071 root->layer()->SetVisible(visible);
1074 void Widget::OnNativeWidgetCreated(bool desktop_widget) {
1076 focus_manager_.reset(FocusManagerFactory::Create(this, desktop_widget));
1078 native_widget_->InitModalType(widget_delegate_->GetModalType());
1080 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetCreated(this));
1083 void Widget::OnNativeWidgetDestroying() {
1084 // Tell the focus manager (if any) that root_view is being removed
1085 // in case that the focused view is under this root view.
1086 if (GetFocusManager())
1087 GetFocusManager()->ViewRemoved(root_view_.get());
1088 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetDestroying(this));
1089 if (non_client_view_)
1090 non_client_view_->WindowClosing();
1091 widget_delegate_->WindowClosing();
1094 void Widget::OnNativeWidgetDestroyed() {
1095 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetDestroyed(this));
1096 widget_delegate_->DeleteDelegate();
1097 widget_delegate_ = NULL;
1098 native_widget_destroyed_ = true;
1101 gfx::Size Widget::GetMinimumSize() const {
1102 return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size();
1105 gfx::Size Widget::GetMaximumSize() const {
1106 return non_client_view_ ? non_client_view_->GetMaximumSize() : gfx::Size();
1109 void Widget::OnNativeWidgetMove() {
1110 widget_delegate_->OnWidgetMove();
1111 View* root = GetRootView();
1112 if (root && root->GetFocusManager()) {
1113 View* focused_view = root->GetFocusManager()->GetFocusedView();
1114 if (focused_view && focused_view->GetInputMethod())
1115 focused_view->GetInputMethod()->OnCaretBoundsChanged(focused_view);
1117 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged(
1119 GetWindowBoundsInScreen()));
1122 void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) {
1123 View* root = GetRootView();
1125 root->SetSize(new_size);
1126 if (root->GetFocusManager()) {
1127 View* focused_view = GetRootView()->GetFocusManager()->GetFocusedView();
1128 if (focused_view && focused_view->GetInputMethod())
1129 focused_view->GetInputMethod()->OnCaretBoundsChanged(focused_view);
1132 SaveWindowPlacementIfInitialized();
1134 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged(
1136 GetWindowBoundsInScreen()));
1139 void Widget::OnNativeWidgetWindowShowStateChanged() {
1140 SaveWindowPlacementIfInitialized();
1143 void Widget::OnNativeWidgetBeginUserBoundsChange() {
1144 widget_delegate_->OnWindowBeginUserBoundsChange();
1147 void Widget::OnNativeWidgetEndUserBoundsChange() {
1148 widget_delegate_->OnWindowEndUserBoundsChange();
1151 bool Widget::HasFocusManager() const {
1152 return !!focus_manager_.get();
1155 bool Widget::OnNativeWidgetPaintAccelerated(const gfx::Rect& dirty_region) {
1156 ui::Compositor* compositor = GetCompositor();
1160 compositor->ScheduleRedrawRect(dirty_region);
1164 void Widget::OnNativeWidgetPaint(gfx::Canvas* canvas) {
1165 // On Linux Aura, we can get here during Init() because of the
1166 // SetInitialBounds call.
1167 if (native_widget_initialized_)
1168 GetRootView()->Paint(canvas, CullSet());
1171 int Widget::GetNonClientComponent(const gfx::Point& point) {
1172 int component = non_client_view_ ?
1173 non_client_view_->NonClientHitTest(point) :
1176 if (movement_disabled_ && (component == HTCAPTION || component == HTSYSMENU))
1182 void Widget::OnKeyEvent(ui::KeyEvent* event) {
1183 SendEventToProcessor(event);
1186 // TODO(tdanderson): We should not be calling the OnMouse*() functions on
1187 // RootView from anywhere in Widget. Use
1188 // SendEventToProcessor() instead. See crbug.com/348087.
1189 void Widget::OnMouseEvent(ui::MouseEvent* event) {
1190 View* root_view = GetRootView();
1191 switch (event->type()) {
1192 case ui::ET_MOUSE_PRESSED: {
1193 last_mouse_event_was_move_ = false;
1195 // We may get deleted by the time we return from OnMousePressed. So we
1196 // use an observer to make sure we are still alive.
1197 WidgetDeletionObserver widget_deletion_observer(this);
1199 // Make sure we're still visible before we attempt capture as the mouse
1200 // press processing may have made the window hide (as happens with menus).
1202 // It is possible for a View to show a context menu on mouse-press. Since
1203 // the menu does a capture and starts a nested message-loop, the release
1204 // would go to the menu. The next click (i.e. both mouse-press and release
1205 // events) also go to the menu. The menu (and the nested message-loop)
1206 // gets closed after this second release event. The code then resumes from
1207 // here. So make sure that the mouse-button is still down before doing a
1209 if (root_view && root_view->OnMousePressed(*event) &&
1210 widget_deletion_observer.IsWidgetAlive() && IsVisible() &&
1211 internal::NativeWidgetPrivate::IsMouseButtonDown()) {
1212 is_mouse_button_pressed_ = true;
1213 if (!native_widget_->HasCapture())
1214 native_widget_->SetCapture();
1215 event->SetHandled();
1220 case ui::ET_MOUSE_RELEASED:
1221 last_mouse_event_was_move_ = false;
1222 is_mouse_button_pressed_ = false;
1223 // Release capture first, to avoid confusion if OnMouseReleased blocks.
1224 if (auto_release_capture_ && native_widget_->HasCapture()) {
1225 base::AutoReset<bool> resetter(&ignore_capture_loss_, true);
1226 native_widget_->ReleaseCapture();
1229 root_view->OnMouseReleased(*event);
1230 if ((event->flags() & ui::EF_IS_NON_CLIENT) == 0)
1231 event->SetHandled();
1234 case ui::ET_MOUSE_MOVED:
1235 case ui::ET_MOUSE_DRAGGED:
1236 if (native_widget_->HasCapture() && is_mouse_button_pressed_) {
1237 last_mouse_event_was_move_ = false;
1239 root_view->OnMouseDragged(*event);
1240 } else if (!last_mouse_event_was_move_ ||
1241 last_mouse_event_position_ != event->location()) {
1242 last_mouse_event_position_ = event->location();
1243 last_mouse_event_was_move_ = true;
1245 root_view->OnMouseMoved(*event);
1249 case ui::ET_MOUSE_EXITED:
1250 last_mouse_event_was_move_ = false;
1252 root_view->OnMouseExited(*event);
1255 case ui::ET_MOUSEWHEEL:
1256 if (root_view && root_view->OnMouseWheel(
1257 static_cast<const ui::MouseWheelEvent&>(*event)))
1258 event->SetHandled();
1266 void Widget::OnMouseCaptureLost() {
1267 if (ignore_capture_loss_)
1270 View* root_view = GetRootView();
1272 root_view->OnMouseCaptureLost();
1273 is_mouse_button_pressed_ = false;
1276 void Widget::OnScrollEvent(ui::ScrollEvent* event) {
1277 ui::ScrollEvent event_copy(*event);
1278 SendEventToProcessor(&event_copy);
1280 // Convert unhandled ui::ET_SCROLL events into ui::ET_MOUSEWHEEL events.
1281 if (!event_copy.handled() && event_copy.type() == ui::ET_SCROLL) {
1282 ui::MouseWheelEvent wheel(*event);
1283 OnMouseEvent(&wheel);
1287 void Widget::OnGestureEvent(ui::GestureEvent* event) {
1288 // We explicitly do not capture here. Not capturing enables multiple widgets
1289 // to get tap events at the same time. Views (such as tab dragging) may
1290 // explicitly capture.
1291 SendEventToProcessor(event);
1294 bool Widget::ExecuteCommand(int command_id) {
1295 return widget_delegate_->ExecuteWindowsCommand(command_id);
1298 InputMethod* Widget::GetInputMethodDirect() {
1299 return input_method_.get();
1302 const std::vector<ui::Layer*>& Widget::GetRootLayers() {
1303 if (root_layers_dirty_) {
1304 root_layers_dirty_ = false;
1305 root_layers_.clear();
1306 BuildRootLayers(GetRootView(), &root_layers_);
1308 return root_layers_;
1311 bool Widget::HasHitTestMask() const {
1312 return widget_delegate_->WidgetHasHitTestMask();
1315 void Widget::GetHitTestMask(gfx::Path* mask) const {
1317 widget_delegate_->GetWidgetHitTestMask(mask);
1320 Widget* Widget::AsWidget() {
1324 const Widget* Widget::AsWidget() const {
1328 bool Widget::SetInitialFocus(ui::WindowShowState show_state) {
1329 View* v = widget_delegate_->GetInitiallyFocusedView();
1330 if (!focus_on_creation_ || show_state == ui::SHOW_STATE_INACTIVE ||
1331 show_state == ui::SHOW_STATE_MINIMIZED) {
1332 // If not focusing the window now, tell the focus manager which view to
1333 // focus when the window is restored.
1335 focus_manager_->SetStoredFocusView(v);
1343 ////////////////////////////////////////////////////////////////////////////////
1344 // Widget, ui::EventSource implementation:
1345 ui::EventProcessor* Widget::GetEventProcessor() {
1346 return root_view_.get();
1349 ////////////////////////////////////////////////////////////////////////////////
1350 // Widget, FocusTraversable implementation:
1352 FocusSearch* Widget::GetFocusSearch() {
1353 return root_view_->GetFocusSearch();
1356 FocusTraversable* Widget::GetFocusTraversableParent() {
1357 // We are a proxy to the root view, so we should be bypassed when traversing
1358 // up and as a result this should not be called.
1363 View* Widget::GetFocusTraversableParentView() {
1364 // We are a proxy to the root view, so we should be bypassed when traversing
1365 // up and as a result this should not be called.
1370 ////////////////////////////////////////////////////////////////////////////////
1371 // Widget, ui::NativeThemeObserver implementation:
1373 void Widget::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) {
1374 DCHECK(observer_manager_.IsObserving(observed_theme));
1376 ui::NativeTheme* current_native_theme = GetNativeTheme();
1377 if (!observer_manager_.IsObserving(current_native_theme)) {
1378 observer_manager_.RemoveAll();
1379 observer_manager_.Add(current_native_theme);
1382 root_view_->PropagateNativeThemeChanged(current_native_theme);
1385 ////////////////////////////////////////////////////////////////////////////////
1386 // Widget, protected:
1388 internal::RootView* Widget::CreateRootView() {
1389 return new internal::RootView(this);
1392 void Widget::DestroyRootView() {
1393 non_client_view_ = NULL;
1395 // Input method has to be destroyed before focus manager.
1396 input_method_.reset();
1399 void Widget::OnDragWillStart() {
1402 void Widget::OnDragComplete() {
1405 ////////////////////////////////////////////////////////////////////////////////
1408 void Widget::SetInactiveRenderingDisabled(bool value) {
1409 if (value == disable_inactive_rendering_)
1412 disable_inactive_rendering_ = value;
1413 if (non_client_view_)
1414 non_client_view_->SetInactiveRenderingDisabled(value);
1417 void Widget::SaveWindowPlacement() {
1418 // The window delegate does the actual saving for us. It seems like (judging
1419 // by go/crash) that in some circumstances we can end up here after
1420 // WM_DESTROY, at which point the window delegate is likely gone. So just
1422 if (!widget_delegate_)
1425 ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL;
1427 native_widget_->GetWindowPlacement(&bounds, &show_state);
1428 widget_delegate_->SaveWindowPlacement(bounds, show_state);
1431 void Widget::SaveWindowPlacementIfInitialized() {
1432 if (native_widget_initialized_)
1433 SaveWindowPlacement();
1436 void Widget::SetInitialBounds(const gfx::Rect& bounds) {
1437 if (!non_client_view_)
1440 gfx::Rect saved_bounds;
1441 if (GetSavedWindowPlacement(&saved_bounds, &saved_show_state_)) {
1442 if (saved_show_state_ == ui::SHOW_STATE_MAXIMIZED) {
1443 // If we're going to maximize, wait until Show is invoked to set the
1444 // bounds. That way we avoid a noticeable resize.
1445 initial_restored_bounds_ = saved_bounds;
1446 } else if (!saved_bounds.IsEmpty()) {
1447 // If the saved bounds are valid, use them.
1448 SetBounds(saved_bounds);
1451 if (bounds.IsEmpty()) {
1452 // No initial bounds supplied, so size the window to its content and
1453 // center over its parent.
1454 native_widget_->CenterWindow(non_client_view_->GetPreferredSize());
1456 // Use the supplied initial bounds.
1457 SetBoundsConstrained(bounds);
1462 void Widget::SetInitialBoundsForFramelessWindow(const gfx::Rect& bounds) {
1463 if (bounds.IsEmpty()) {
1464 View* contents_view = GetContentsView();
1465 DCHECK(contents_view);
1466 // No initial bounds supplied, so size the window to its content and
1467 // center over its parent if preferred size is provided.
1468 gfx::Size size = contents_view->GetPreferredSize();
1469 if (!size.IsEmpty())
1470 native_widget_->CenterWindow(size);
1472 // Use the supplied initial bounds.
1473 SetBoundsConstrained(bounds);
1477 bool Widget::GetSavedWindowPlacement(gfx::Rect* bounds,
1478 ui::WindowShowState* show_state) {
1479 // First we obtain the window's saved show-style and store it. We need to do
1480 // this here, rather than in Show() because by the time Show() is called,
1481 // the window's size will have been reset (below) and the saved maximized
1482 // state will have been lost. Sadly there's no way to tell on Windows when
1483 // a window is restored from maximized state, so we can't more accurately
1484 // track maximized state independently of sizing information.
1486 // Restore the window's placement from the controller.
1487 if (widget_delegate_->GetSavedWindowPlacement(this, bounds, show_state)) {
1488 if (!widget_delegate_->ShouldRestoreWindowSize()) {
1489 bounds->set_size(non_client_view_->GetPreferredSize());
1491 gfx::Size minimum_size = GetMinimumSize();
1492 // Make sure the bounds are at least the minimum size.
1493 if (bounds->width() < minimum_size.width())
1494 bounds->set_width(minimum_size.width());
1496 if (bounds->height() < minimum_size.height())
1497 bounds->set_height(minimum_size.height());
1504 scoped_ptr<InputMethod> Widget::CreateInputMethod() {
1505 scoped_ptr<InputMethod> input_method(native_widget_->CreateInputMethod());
1506 if (input_method.get())
1507 input_method->Init(this);
1508 return input_method.Pass();
1511 void Widget::ReplaceInputMethod(InputMethod* input_method) {
1512 input_method_.reset(input_method);
1513 input_method->SetDelegate(native_widget_->GetInputMethodDelegate());
1514 input_method->Init(this);
1517 namespace internal {
1519 ////////////////////////////////////////////////////////////////////////////////
1520 // internal::NativeWidgetPrivate, NativeWidget implementation:
1522 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() {
1526 } // namespace internal
1527 } // namespace views