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::OnSizeConstraintsChanged() {
997 native_widget_->OnSizeConstraintsChanged();
998 non_client_view_->SizeConstraintsChanged();
1001 void Widget::OnOwnerClosing() {
1004 ////////////////////////////////////////////////////////////////////////////////
1005 // Widget, NativeWidgetDelegate implementation:
1007 bool Widget::IsModal() const {
1008 return widget_delegate_->GetModalType() != ui::MODAL_TYPE_NONE;
1011 bool Widget::IsDialogBox() const {
1012 return !!widget_delegate_->AsDialogDelegate();
1015 bool Widget::CanActivate() const {
1016 return widget_delegate_->CanActivate();
1019 bool Widget::IsInactiveRenderingDisabled() const {
1020 return disable_inactive_rendering_;
1023 void Widget::EnableInactiveRendering() {
1024 SetInactiveRenderingDisabled(false);
1027 void Widget::OnNativeWidgetActivationChanged(bool active) {
1028 // On windows we may end up here before we've completed initialization (from
1029 // an WM_NCACTIVATE). If that happens the WidgetDelegate likely doesn't know
1030 // the Widget and will crash attempting to access it.
1031 if (!active && native_widget_initialized_)
1032 SaveWindowPlacement();
1034 FOR_EACH_OBSERVER(WidgetObserver, observers_,
1035 OnWidgetActivationChanged(this, active));
1037 // During window creation, the widget gets focused without activation, and in
1038 // that case, the focus manager cannot set the appropriate text input client
1039 // because the widget is not active. Thus we have to notify the focus manager
1040 // not only when the focus changes but also when the widget gets activated.
1041 // See crbug.com/377479 for details.
1042 views::FocusManager* focus_manager = GetFocusManager();
1043 if (focus_manager) {
1045 focus_manager->FocusTextInputClient(focus_manager->GetFocusedView());
1047 focus_manager->BlurTextInputClient(focus_manager->GetFocusedView());
1050 if (IsVisible() && non_client_view())
1051 non_client_view()->frame_view()->SchedulePaint();
1054 void Widget::OnNativeFocus(gfx::NativeView old_focused_view) {
1055 WidgetFocusManager::GetInstance()->OnWidgetFocusEvent(old_focused_view,
1059 void Widget::OnNativeBlur(gfx::NativeView new_focused_view) {
1060 WidgetFocusManager::GetInstance()->OnWidgetFocusEvent(GetNativeView(),
1064 void Widget::OnNativeWidgetVisibilityChanging(bool visible) {
1065 FOR_EACH_OBSERVER(WidgetObserver, observers_,
1066 OnWidgetVisibilityChanging(this, visible));
1069 void Widget::OnNativeWidgetVisibilityChanged(bool visible) {
1070 View* root = GetRootView();
1072 root->PropagateVisibilityNotifications(root, visible);
1073 FOR_EACH_OBSERVER(WidgetObserver, observers_,
1074 OnWidgetVisibilityChanged(this, visible));
1075 if (GetCompositor() && root && root->layer())
1076 root->layer()->SetVisible(visible);
1079 void Widget::OnNativeWidgetCreated(bool desktop_widget) {
1081 focus_manager_.reset(FocusManagerFactory::Create(this, desktop_widget));
1083 native_widget_->InitModalType(widget_delegate_->GetModalType());
1085 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetCreated(this));
1088 void Widget::OnNativeWidgetDestroying() {
1089 // Tell the focus manager (if any) that root_view is being removed
1090 // in case that the focused view is under this root view.
1091 if (GetFocusManager())
1092 GetFocusManager()->ViewRemoved(root_view_.get());
1093 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetDestroying(this));
1094 if (non_client_view_)
1095 non_client_view_->WindowClosing();
1096 widget_delegate_->WindowClosing();
1099 void Widget::OnNativeWidgetDestroyed() {
1100 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetDestroyed(this));
1101 widget_delegate_->DeleteDelegate();
1102 widget_delegate_ = NULL;
1103 native_widget_destroyed_ = true;
1106 gfx::Size Widget::GetMinimumSize() const {
1107 return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size();
1110 gfx::Size Widget::GetMaximumSize() const {
1111 return non_client_view_ ? non_client_view_->GetMaximumSize() : gfx::Size();
1114 void Widget::OnNativeWidgetMove() {
1115 widget_delegate_->OnWidgetMove();
1116 View* root = GetRootView();
1117 if (root && root->GetFocusManager()) {
1118 View* focused_view = root->GetFocusManager()->GetFocusedView();
1119 if (focused_view && focused_view->GetInputMethod())
1120 focused_view->GetInputMethod()->OnCaretBoundsChanged(focused_view);
1122 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged(
1124 GetWindowBoundsInScreen()));
1127 void Widget::OnNativeWidgetSizeChanged(const gfx::Size& new_size) {
1128 View* root = GetRootView();
1130 root->SetSize(new_size);
1131 if (root->GetFocusManager()) {
1132 View* focused_view = GetRootView()->GetFocusManager()->GetFocusedView();
1133 if (focused_view && focused_view->GetInputMethod())
1134 focused_view->GetInputMethod()->OnCaretBoundsChanged(focused_view);
1137 SaveWindowPlacementIfInitialized();
1139 FOR_EACH_OBSERVER(WidgetObserver, observers_, OnWidgetBoundsChanged(
1141 GetWindowBoundsInScreen()));
1144 void Widget::OnNativeWidgetWindowShowStateChanged() {
1145 SaveWindowPlacementIfInitialized();
1148 void Widget::OnNativeWidgetBeginUserBoundsChange() {
1149 widget_delegate_->OnWindowBeginUserBoundsChange();
1152 void Widget::OnNativeWidgetEndUserBoundsChange() {
1153 widget_delegate_->OnWindowEndUserBoundsChange();
1156 bool Widget::HasFocusManager() const {
1157 return !!focus_manager_.get();
1160 bool Widget::OnNativeWidgetPaintAccelerated(const gfx::Rect& dirty_region) {
1161 ui::Compositor* compositor = GetCompositor();
1165 compositor->ScheduleRedrawRect(dirty_region);
1169 void Widget::OnNativeWidgetPaint(gfx::Canvas* canvas) {
1170 // On Linux Aura, we can get here during Init() because of the
1171 // SetInitialBounds call.
1172 if (native_widget_initialized_)
1173 GetRootView()->Paint(canvas, CullSet());
1176 int Widget::GetNonClientComponent(const gfx::Point& point) {
1177 int component = non_client_view_ ?
1178 non_client_view_->NonClientHitTest(point) :
1181 if (movement_disabled_ && (component == HTCAPTION || component == HTSYSMENU))
1187 void Widget::OnKeyEvent(ui::KeyEvent* event) {
1188 SendEventToProcessor(event);
1191 // TODO(tdanderson): We should not be calling the OnMouse*() functions on
1192 // RootView from anywhere in Widget. Use
1193 // SendEventToProcessor() instead. See crbug.com/348087.
1194 void Widget::OnMouseEvent(ui::MouseEvent* event) {
1195 View* root_view = GetRootView();
1196 switch (event->type()) {
1197 case ui::ET_MOUSE_PRESSED: {
1198 last_mouse_event_was_move_ = false;
1200 // We may get deleted by the time we return from OnMousePressed. So we
1201 // use an observer to make sure we are still alive.
1202 WidgetDeletionObserver widget_deletion_observer(this);
1204 // Make sure we're still visible before we attempt capture as the mouse
1205 // press processing may have made the window hide (as happens with menus).
1207 // It is possible for a View to show a context menu on mouse-press. Since
1208 // the menu does a capture and starts a nested message-loop, the release
1209 // would go to the menu. The next click (i.e. both mouse-press and release
1210 // events) also go to the menu. The menu (and the nested message-loop)
1211 // gets closed after this second release event. The code then resumes from
1212 // here. So make sure that the mouse-button is still down before doing a
1214 if (root_view && root_view->OnMousePressed(*event) &&
1215 widget_deletion_observer.IsWidgetAlive() && IsVisible() &&
1216 internal::NativeWidgetPrivate::IsMouseButtonDown()) {
1217 is_mouse_button_pressed_ = true;
1218 if (!native_widget_->HasCapture())
1219 native_widget_->SetCapture();
1220 event->SetHandled();
1225 case ui::ET_MOUSE_RELEASED:
1226 last_mouse_event_was_move_ = false;
1227 is_mouse_button_pressed_ = false;
1228 // Release capture first, to avoid confusion if OnMouseReleased blocks.
1229 if (auto_release_capture_ && native_widget_->HasCapture()) {
1230 base::AutoReset<bool> resetter(&ignore_capture_loss_, true);
1231 native_widget_->ReleaseCapture();
1234 root_view->OnMouseReleased(*event);
1235 if ((event->flags() & ui::EF_IS_NON_CLIENT) == 0)
1236 event->SetHandled();
1239 case ui::ET_MOUSE_MOVED:
1240 case ui::ET_MOUSE_DRAGGED:
1241 if (native_widget_->HasCapture() && is_mouse_button_pressed_) {
1242 last_mouse_event_was_move_ = false;
1244 root_view->OnMouseDragged(*event);
1245 } else if (!last_mouse_event_was_move_ ||
1246 last_mouse_event_position_ != event->location()) {
1247 last_mouse_event_position_ = event->location();
1248 last_mouse_event_was_move_ = true;
1250 root_view->OnMouseMoved(*event);
1254 case ui::ET_MOUSE_EXITED:
1255 last_mouse_event_was_move_ = false;
1257 root_view->OnMouseExited(*event);
1260 case ui::ET_MOUSEWHEEL:
1261 if (root_view && root_view->OnMouseWheel(
1262 static_cast<const ui::MouseWheelEvent&>(*event)))
1263 event->SetHandled();
1271 void Widget::OnMouseCaptureLost() {
1272 if (ignore_capture_loss_)
1275 View* root_view = GetRootView();
1277 root_view->OnMouseCaptureLost();
1278 is_mouse_button_pressed_ = false;
1281 void Widget::OnScrollEvent(ui::ScrollEvent* event) {
1282 ui::ScrollEvent event_copy(*event);
1283 SendEventToProcessor(&event_copy);
1285 // Convert unhandled ui::ET_SCROLL events into ui::ET_MOUSEWHEEL events.
1286 if (!event_copy.handled() && event_copy.type() == ui::ET_SCROLL) {
1287 ui::MouseWheelEvent wheel(*event);
1288 OnMouseEvent(&wheel);
1292 void Widget::OnGestureEvent(ui::GestureEvent* event) {
1293 // We explicitly do not capture here. Not capturing enables multiple widgets
1294 // to get tap events at the same time. Views (such as tab dragging) may
1295 // explicitly capture.
1296 SendEventToProcessor(event);
1299 bool Widget::ExecuteCommand(int command_id) {
1300 return widget_delegate_->ExecuteWindowsCommand(command_id);
1303 InputMethod* Widget::GetInputMethodDirect() {
1304 return input_method_.get();
1307 const std::vector<ui::Layer*>& Widget::GetRootLayers() {
1308 if (root_layers_dirty_) {
1309 root_layers_dirty_ = false;
1310 root_layers_.clear();
1311 BuildRootLayers(GetRootView(), &root_layers_);
1313 return root_layers_;
1316 bool Widget::HasHitTestMask() const {
1317 return widget_delegate_->WidgetHasHitTestMask();
1320 void Widget::GetHitTestMask(gfx::Path* mask) const {
1322 widget_delegate_->GetWidgetHitTestMask(mask);
1325 Widget* Widget::AsWidget() {
1329 const Widget* Widget::AsWidget() const {
1333 bool Widget::SetInitialFocus(ui::WindowShowState show_state) {
1334 View* v = widget_delegate_->GetInitiallyFocusedView();
1335 if (!focus_on_creation_ || show_state == ui::SHOW_STATE_INACTIVE ||
1336 show_state == ui::SHOW_STATE_MINIMIZED) {
1337 // If not focusing the window now, tell the focus manager which view to
1338 // focus when the window is restored.
1340 focus_manager_->SetStoredFocusView(v);
1348 ////////////////////////////////////////////////////////////////////////////////
1349 // Widget, ui::EventSource implementation:
1350 ui::EventProcessor* Widget::GetEventProcessor() {
1351 return root_view_.get();
1354 ////////////////////////////////////////////////////////////////////////////////
1355 // Widget, FocusTraversable implementation:
1357 FocusSearch* Widget::GetFocusSearch() {
1358 return root_view_->GetFocusSearch();
1361 FocusTraversable* Widget::GetFocusTraversableParent() {
1362 // We are a proxy to the root view, so we should be bypassed when traversing
1363 // up and as a result this should not be called.
1368 View* Widget::GetFocusTraversableParentView() {
1369 // We are a proxy to the root view, so we should be bypassed when traversing
1370 // up and as a result this should not be called.
1375 ////////////////////////////////////////////////////////////////////////////////
1376 // Widget, ui::NativeThemeObserver implementation:
1378 void Widget::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) {
1379 DCHECK(observer_manager_.IsObserving(observed_theme));
1381 ui::NativeTheme* current_native_theme = GetNativeTheme();
1382 if (!observer_manager_.IsObserving(current_native_theme)) {
1383 observer_manager_.RemoveAll();
1384 observer_manager_.Add(current_native_theme);
1387 root_view_->PropagateNativeThemeChanged(current_native_theme);
1390 ////////////////////////////////////////////////////////////////////////////////
1391 // Widget, protected:
1393 internal::RootView* Widget::CreateRootView() {
1394 return new internal::RootView(this);
1397 void Widget::DestroyRootView() {
1398 non_client_view_ = NULL;
1400 // Input method has to be destroyed before focus manager.
1401 input_method_.reset();
1404 void Widget::OnDragWillStart() {
1407 void Widget::OnDragComplete() {
1410 ////////////////////////////////////////////////////////////////////////////////
1413 void Widget::SetInactiveRenderingDisabled(bool value) {
1414 if (value == disable_inactive_rendering_)
1417 disable_inactive_rendering_ = value;
1418 if (non_client_view_)
1419 non_client_view_->SetInactiveRenderingDisabled(value);
1422 void Widget::SaveWindowPlacement() {
1423 // The window delegate does the actual saving for us. It seems like (judging
1424 // by go/crash) that in some circumstances we can end up here after
1425 // WM_DESTROY, at which point the window delegate is likely gone. So just
1427 if (!widget_delegate_)
1430 ui::WindowShowState show_state = ui::SHOW_STATE_NORMAL;
1432 native_widget_->GetWindowPlacement(&bounds, &show_state);
1433 widget_delegate_->SaveWindowPlacement(bounds, show_state);
1436 void Widget::SaveWindowPlacementIfInitialized() {
1437 if (native_widget_initialized_)
1438 SaveWindowPlacement();
1441 void Widget::SetInitialBounds(const gfx::Rect& bounds) {
1442 if (!non_client_view_)
1445 gfx::Rect saved_bounds;
1446 if (GetSavedWindowPlacement(&saved_bounds, &saved_show_state_)) {
1447 if (saved_show_state_ == ui::SHOW_STATE_MAXIMIZED) {
1448 // If we're going to maximize, wait until Show is invoked to set the
1449 // bounds. That way we avoid a noticeable resize.
1450 initial_restored_bounds_ = saved_bounds;
1451 } else if (!saved_bounds.IsEmpty()) {
1452 // If the saved bounds are valid, use them.
1453 SetBounds(saved_bounds);
1456 if (bounds.IsEmpty()) {
1457 // No initial bounds supplied, so size the window to its content and
1458 // center over its parent.
1459 native_widget_->CenterWindow(non_client_view_->GetPreferredSize());
1461 // Use the supplied initial bounds.
1462 SetBoundsConstrained(bounds);
1467 void Widget::SetInitialBoundsForFramelessWindow(const gfx::Rect& bounds) {
1468 if (bounds.IsEmpty()) {
1469 View* contents_view = GetContentsView();
1470 DCHECK(contents_view);
1471 // No initial bounds supplied, so size the window to its content and
1472 // center over its parent if preferred size is provided.
1473 gfx::Size size = contents_view->GetPreferredSize();
1474 if (!size.IsEmpty())
1475 native_widget_->CenterWindow(size);
1477 // Use the supplied initial bounds.
1478 SetBoundsConstrained(bounds);
1482 bool Widget::GetSavedWindowPlacement(gfx::Rect* bounds,
1483 ui::WindowShowState* show_state) {
1484 // First we obtain the window's saved show-style and store it. We need to do
1485 // this here, rather than in Show() because by the time Show() is called,
1486 // the window's size will have been reset (below) and the saved maximized
1487 // state will have been lost. Sadly there's no way to tell on Windows when
1488 // a window is restored from maximized state, so we can't more accurately
1489 // track maximized state independently of sizing information.
1491 // Restore the window's placement from the controller.
1492 if (widget_delegate_->GetSavedWindowPlacement(this, bounds, show_state)) {
1493 if (!widget_delegate_->ShouldRestoreWindowSize()) {
1494 bounds->set_size(non_client_view_->GetPreferredSize());
1496 gfx::Size minimum_size = GetMinimumSize();
1497 // Make sure the bounds are at least the minimum size.
1498 if (bounds->width() < minimum_size.width())
1499 bounds->set_width(minimum_size.width());
1501 if (bounds->height() < minimum_size.height())
1502 bounds->set_height(minimum_size.height());
1509 scoped_ptr<InputMethod> Widget::CreateInputMethod() {
1510 scoped_ptr<InputMethod> input_method(native_widget_->CreateInputMethod());
1511 if (input_method.get())
1512 input_method->Init(this);
1513 return input_method.Pass();
1516 void Widget::ReplaceInputMethod(InputMethod* input_method) {
1517 input_method_.reset(input_method);
1518 input_method->SetDelegate(native_widget_->GetInputMethodDelegate());
1519 input_method->Init(this);
1522 namespace internal {
1524 ////////////////////////////////////////////////////////////////////////////////
1525 // internal::NativeWidgetPrivate, NativeWidget implementation:
1527 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() {
1531 } // namespace internal
1532 } // namespace views