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/logging.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/trace_event/trace_event.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/ime/input_method.h"
15 #include "ui/base/l10n/l10n_font_util.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/compositor/compositor.h"
18 #include "ui/compositor/layer.h"
19 #include "ui/events/event.h"
20 #include "ui/events/event_utils.h"
21 #include "ui/gfx/image/image_skia.h"
22 #include "ui/gfx/screen.h"
23 #include "ui/views/controls/menu/menu_controller.h"
24 #include "ui/views/event_monitor.h"
25 #include "ui/views/focus/focus_manager.h"
26 #include "ui/views/focus/focus_manager_factory.h"
27 #include "ui/views/focus/view_storage.h"
28 #include "ui/views/focus/widget_focus_manager.h"
29 #include "ui/views/views_delegate.h"
30 #include "ui/views/widget/native_widget_private.h"
31 #include "ui/views/widget/root_view.h"
32 #include "ui/views/widget/tooltip_manager.h"
33 #include "ui/views/widget/widget_delegate.h"
34 #include "ui/views/widget/widget_deletion_observer.h"
35 #include "ui/views/widget/widget_observer.h"
36 #include "ui/views/widget/widget_removals_observer.h"
37 #include "ui/views/window/custom_frame_view.h"
38 #include "ui/views/window/dialog_delegate.h"
44 // If |view| has a layer the layer is added to |layers|. Else this recurses
45 // through the children. This is used to build a list of the layers created by
46 // views that are direct children of the Widgets layer.
47 void BuildRootLayers(View
* view
, std::vector
<ui::Layer
*>* layers
) {
49 layers
->push_back(view
->layer());
51 for (int i
= 0; i
< view
->child_count(); ++i
)
52 BuildRootLayers(view
->child_at(i
), layers
);
56 // Create a native widget implementation.
57 // First, use the supplied one if non-NULL.
58 // Finally, make a default one.
59 NativeWidget
* CreateNativeWidget(NativeWidget
* native_widget
,
60 internal::NativeWidgetDelegate
* delegate
) {
63 internal::NativeWidgetPrivate::CreateNativeWidget(delegate
);
68 void NotifyCaretBoundsChanged(ui::InputMethod
* input_method
) {
71 ui::TextInputClient
* client
= input_method
->GetTextInputClient();
73 input_method
->OnCaretBoundsChanged(client
);
78 // A default implementation of WidgetDelegate, used by Widget when no
79 // WidgetDelegate is supplied.
80 class DefaultWidgetDelegate
: public WidgetDelegate
{
82 explicit DefaultWidgetDelegate(Widget
* widget
) : widget_(widget
) {
84 ~DefaultWidgetDelegate() override
{}
86 // Overridden from WidgetDelegate:
87 void DeleteDelegate() override
{ delete this; }
88 Widget
* GetWidget() override
{ return widget_
; }
89 const Widget
* GetWidget() const override
{ return widget_
; }
90 bool ShouldAdvanceFocusToTopLevelWidget() const override
{
91 // In most situations where a Widget is used without a delegate the Widget
92 // is used as a container, so that we want focus to advance to the top-level
93 // widget. A good example of this is the find bar.
100 DISALLOW_COPY_AND_ASSIGN(DefaultWidgetDelegate
);
103 ////////////////////////////////////////////////////////////////////////////////
104 // Widget, InitParams:
106 Widget::InitParams::InitParams()
110 opacity(INFER_OPACITY
),
112 activatable(ACTIVATABLE_DEFAULT
),
114 visible_on_all_workspaces(false),
115 ownership(NATIVE_WIDGET_OWNS_WIDGET
),
116 mirror_origin_in_rtl(false),
117 shadow_type(SHADOW_TYPE_DEFAULT
),
118 remove_standard_frame(false),
119 use_system_default_icon(false),
120 show_state(ui::SHOW_STATE_DEFAULT
),
123 desktop_window_tree_host(NULL
),
124 layer_type(ui::LAYER_TEXTURED
),
126 force_show_in_taskbar(false) {
129 Widget::InitParams::InitParams(Type type
)
133 opacity(INFER_OPACITY
),
135 activatable(ACTIVATABLE_DEFAULT
),
136 keep_on_top(type
== TYPE_MENU
|| type
== TYPE_DRAG
),
137 visible_on_all_workspaces(false),
138 ownership(NATIVE_WIDGET_OWNS_WIDGET
),
139 mirror_origin_in_rtl(false),
140 shadow_type(SHADOW_TYPE_DEFAULT
),
141 remove_standard_frame(false),
142 use_system_default_icon(false),
143 show_state(ui::SHOW_STATE_DEFAULT
),
146 desktop_window_tree_host(NULL
),
147 layer_type(ui::LAYER_TEXTURED
),
149 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::GetInstance())
327 ViewsDelegate::GetInstance()->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 icon and title before setting the window's
370 // initial bounds; the frame view's preferred height may depend on the
371 // presence of an icon or a title.
374 non_client_view_
->ResetWindowControls();
375 SetInitialBounds(params
.bounds
);
376 if (params
.show_state
== ui::SHOW_STATE_MAXIMIZED
)
378 else if (params
.show_state
== ui::SHOW_STATE_MINIMIZED
)
380 } else if (params
.delegate
) {
381 SetContentsView(params
.delegate
->GetContentsView());
382 SetInitialBoundsForFramelessWindow(params
.bounds
);
384 // This must come after SetContentsView() or it might not be able to find
385 // the correct NativeTheme (on Linux). See http://crbug.com/384492
386 observer_manager_
.Add(GetNativeTheme());
387 native_widget_initialized_
= true;
390 // Unconverted methods (see header) --------------------------------------------
392 gfx::NativeView
Widget::GetNativeView() const {
393 return native_widget_
->GetNativeView();
396 gfx::NativeWindow
Widget::GetNativeWindow() const {
397 return native_widget_
->GetNativeWindow();
400 void Widget::AddObserver(WidgetObserver
* observer
) {
401 // Make sure that there is no nullptr in observer list. crbug.com/471649.
403 observers_
.AddObserver(observer
);
406 void Widget::RemoveObserver(WidgetObserver
* observer
) {
407 observers_
.RemoveObserver(observer
);
410 bool Widget::HasObserver(const WidgetObserver
* observer
) const {
411 return observers_
.HasObserver(observer
);
414 void Widget::AddRemovalsObserver(WidgetRemovalsObserver
* observer
) {
415 removals_observers_
.AddObserver(observer
);
418 void Widget::RemoveRemovalsObserver(WidgetRemovalsObserver
* observer
) {
419 removals_observers_
.RemoveObserver(observer
);
422 bool Widget::HasRemovalsObserver(const WidgetRemovalsObserver
* observer
) const {
423 return removals_observers_
.HasObserver(observer
);
426 bool Widget::GetAccelerator(int cmd_id
, ui::Accelerator
* accelerator
) const {
430 void Widget::ViewHierarchyChanged(
431 const View::ViewHierarchyChangedDetails
& details
) {
432 if (!details
.is_add
) {
433 if (details
.child
== dragged_view_
)
434 dragged_view_
= NULL
;
435 FocusManager
* focus_manager
= GetFocusManager();
437 focus_manager
->ViewRemoved(details
.child
);
438 ViewStorage::GetInstance()->ViewRemoved(details
.child
);
439 native_widget_
->ViewRemoved(details
.child
);
443 void Widget::NotifyNativeViewHierarchyWillChange() {
444 FocusManager
* focus_manager
= GetFocusManager();
445 // We are being removed from a window hierarchy. Treat this as
446 // the root_view_ being removed.
448 focus_manager
->ViewRemoved(root_view_
.get());
451 void Widget::NotifyNativeViewHierarchyChanged() {
452 root_view_
->NotifyNativeViewHierarchyChanged();
455 void Widget::NotifyWillRemoveView(View
* view
) {
456 FOR_EACH_OBSERVER(WidgetRemovalsObserver
,
458 OnWillRemoveView(this, view
));
461 // Converted methods (see header) ----------------------------------------------
463 Widget
* Widget::GetTopLevelWidget() {
464 return const_cast<Widget
*>(
465 static_cast<const Widget
*>(this)->GetTopLevelWidget());
468 const Widget
* Widget::GetTopLevelWidget() const {
469 // GetTopLevelNativeWidget doesn't work during destruction because
470 // property is gone after gobject gets deleted. Short circuit here
471 // for toplevel so that InputMethod can remove itself from
473 return is_top_level() ? this : native_widget_
->GetTopLevelWidget();
476 void Widget::SetContentsView(View
* view
) {
477 // Do not SetContentsView() again if it is already set to the same view.
478 if (view
== GetContentsView())
480 root_view_
->SetContentsView(view
);
481 if (non_client_view_
!= view
) {
482 // |non_client_view_| can only be non-NULL here if RequiresNonClientView()
483 // was true when the widget was initialized. Creating widgets with non
484 // client views and then setting the contents view can cause subtle
485 // problems on Windows, where the native widget thinks there is still a
486 // |non_client_view_|. If you get this error, either use a different type
487 // when initializing the widget, or don't call SetContentsView().
488 DCHECK(!non_client_view_
);
489 non_client_view_
= NULL
;
493 View
* Widget::GetContentsView() {
494 return root_view_
->GetContentsView();
497 gfx::Rect
Widget::GetWindowBoundsInScreen() const {
498 return native_widget_
->GetWindowBoundsInScreen();
501 gfx::Rect
Widget::GetClientAreaBoundsInScreen() const {
502 return native_widget_
->GetClientAreaBoundsInScreen();
505 gfx::Rect
Widget::GetRestoredBounds() const {
506 return native_widget_
->GetRestoredBounds();
509 void Widget::SetBounds(const gfx::Rect
& bounds
) {
510 native_widget_
->SetBounds(bounds
);
513 void Widget::SetSize(const gfx::Size
& size
) {
514 native_widget_
->SetSize(size
);
517 void Widget::CenterWindow(const gfx::Size
& size
) {
518 native_widget_
->CenterWindow(size
);
521 void Widget::SetBoundsConstrained(const gfx::Rect
& bounds
) {
522 gfx::Rect work_area
=
523 gfx::Screen::GetScreenFor(GetNativeView())->GetDisplayNearestPoint(
524 bounds
.origin()).work_area();
525 if (work_area
.IsEmpty()) {
528 // Inset the work area slightly.
529 work_area
.Inset(10, 10, 10, 10);
530 work_area
.AdjustToFit(bounds
);
531 SetBounds(work_area
);
535 void Widget::SetVisibilityChangedAnimationsEnabled(bool value
) {
536 native_widget_
->SetVisibilityChangedAnimationsEnabled(value
);
539 void Widget::SetVisibilityAnimationDuration(const base::TimeDelta
& duration
) {
540 native_widget_
->SetVisibilityAnimationDuration(duration
);
543 void Widget::SetVisibilityAnimationTransition(VisibilityTransition transition
) {
544 native_widget_
->SetVisibilityAnimationTransition(transition
);
547 Widget::MoveLoopResult
Widget::RunMoveLoop(
548 const gfx::Vector2d
& drag_offset
,
549 MoveLoopSource source
,
550 MoveLoopEscapeBehavior escape_behavior
) {
551 return native_widget_
->RunMoveLoop(drag_offset
, source
, escape_behavior
);
554 void Widget::EndMoveLoop() {
555 native_widget_
->EndMoveLoop();
558 void Widget::StackAboveWidget(Widget
* widget
) {
559 native_widget_
->StackAbove(widget
->GetNativeView());
562 void Widget::StackAbove(gfx::NativeView native_view
) {
563 native_widget_
->StackAbove(native_view
);
566 void Widget::StackAtTop() {
567 native_widget_
->StackAtTop();
570 void Widget::StackBelow(gfx::NativeView native_view
) {
571 native_widget_
->StackBelow(native_view
);
574 void Widget::SetShape(SkRegion
* shape
) {
575 native_widget_
->SetShape(shape
);
578 void Widget::Close() {
579 if (widget_closed_
) {
580 // It appears we can hit this code path if you close a modal dialog then
581 // close the last browser before the destructor is hit, which triggers
582 // invoking Close again.
586 bool can_close
= true;
587 if (non_client_view_
)
588 can_close
= non_client_view_
->CanClose();
590 SaveWindowPlacement();
592 // During tear-down the top-level focus manager becomes unavailable to
593 // GTK tabbed panes and their children, so normal deregistration via
594 // |FormManager::ViewRemoved()| calls are fouled. We clear focus here
595 // to avoid these redundant steps and to avoid accessing deleted views
596 // that may have been in focus.
597 if (is_top_level() && focus_manager_
.get())
598 focus_manager_
->SetFocusedView(NULL
);
600 FOR_EACH_OBSERVER(WidgetObserver
, observers_
, OnWidgetClosing(this));
601 native_widget_
->Close();
602 widget_closed_
= true;
606 void Widget::CloseNow() {
607 FOR_EACH_OBSERVER(WidgetObserver
, observers_
, OnWidgetClosing(this));
608 native_widget_
->CloseNow();
611 bool Widget::IsClosed() const {
612 return widget_closed_
;
615 void Widget::Show() {
616 const ui::Layer
* layer
= GetLayer();
617 TRACE_EVENT1("views", "Widget::Show", "layer",
618 layer
? layer
->name() : "none");
619 if (non_client_view_
) {
620 // While initializing, the kiosk mode will go to full screen before the
621 // widget gets shown. In that case we stay in full screen mode, regardless
622 // of the |saved_show_state_| member.
623 if (saved_show_state_
== ui::SHOW_STATE_MAXIMIZED
&&
624 !initial_restored_bounds_
.IsEmpty() &&
626 native_widget_
->ShowMaximizedWithBounds(initial_restored_bounds_
);
628 native_widget_
->ShowWithWindowState(
629 IsFullscreen() ? ui::SHOW_STATE_FULLSCREEN
: saved_show_state_
);
631 // |saved_show_state_| only applies the first time the window is shown.
632 // If we don't reset the value the window may be shown maximized every time
633 // it is subsequently shown after being hidden.
634 saved_show_state_
= ui::SHOW_STATE_NORMAL
;
637 ? native_widget_
->Show()
638 : native_widget_
->ShowWithWindowState(ui::SHOW_STATE_INACTIVE
);
642 void Widget::Hide() {
643 native_widget_
->Hide();
646 void Widget::ShowInactive() {
647 // If this gets called with saved_show_state_ == ui::SHOW_STATE_MAXIMIZED,
648 // call SetBounds()with the restored bounds to set the correct size. This
649 // normally should not happen, but if it does we should avoid showing unsized
651 if (saved_show_state_
== ui::SHOW_STATE_MAXIMIZED
&&
652 !initial_restored_bounds_
.IsEmpty()) {
653 SetBounds(initial_restored_bounds_
);
654 saved_show_state_
= ui::SHOW_STATE_NORMAL
;
656 native_widget_
->ShowWithWindowState(ui::SHOW_STATE_INACTIVE
);
659 void Widget::Activate() {
660 native_widget_
->Activate();
663 void Widget::Deactivate() {
664 native_widget_
->Deactivate();
667 bool Widget::IsActive() const {
668 return native_widget_
->IsActive();
671 void Widget::DisableInactiveRendering() {
672 SetInactiveRenderingDisabled(true);
675 void Widget::SetAlwaysOnTop(bool on_top
) {
676 native_widget_
->SetAlwaysOnTop(on_top
);
679 bool Widget::IsAlwaysOnTop() const {
680 return native_widget_
->IsAlwaysOnTop();
683 void Widget::SetVisibleOnAllWorkspaces(bool always_visible
) {
684 native_widget_
->SetVisibleOnAllWorkspaces(always_visible
);
687 void Widget::Maximize() {
688 native_widget_
->Maximize();
691 void Widget::Minimize() {
692 native_widget_
->Minimize();
695 void Widget::Restore() {
696 native_widget_
->Restore();
699 bool Widget::IsMaximized() const {
700 return native_widget_
->IsMaximized();
703 bool Widget::IsMinimized() const {
704 return native_widget_
->IsMinimized();
707 void Widget::SetFullscreen(bool fullscreen
) {
708 if (IsFullscreen() == fullscreen
)
711 native_widget_
->SetFullscreen(fullscreen
);
713 if (non_client_view_
)
714 non_client_view_
->Layout();
717 bool Widget::IsFullscreen() const {
718 return native_widget_
->IsFullscreen();
721 void Widget::SetOpacity(unsigned char opacity
) {
722 native_widget_
->SetOpacity(opacity
);
725 void Widget::SetUseDragFrame(bool use_drag_frame
) {
726 native_widget_
->SetUseDragFrame(use_drag_frame
);
729 void Widget::FlashFrame(bool flash
) {
730 native_widget_
->FlashFrame(flash
);
733 View
* Widget::GetRootView() {
734 return root_view_
.get();
737 const View
* Widget::GetRootView() const {
738 return root_view_
.get();
741 bool Widget::IsVisible() const {
742 return native_widget_
->IsVisible();
745 ui::ThemeProvider
* Widget::GetThemeProvider() const {
746 const Widget
* root_widget
= GetTopLevelWidget();
747 if (root_widget
&& root_widget
!= this) {
748 // Attempt to get the theme provider, and fall back to the default theme
749 // provider if not found.
750 ui::ThemeProvider
* provider
= root_widget
->GetThemeProvider();
754 provider
= root_widget
->default_theme_provider_
.get();
758 return default_theme_provider_
.get();
761 const ui::NativeTheme
* Widget::GetNativeTheme() const {
762 return native_widget_
->GetNativeTheme();
765 FocusManager
* Widget::GetFocusManager() {
766 Widget
* toplevel_widget
= GetTopLevelWidget();
767 return toplevel_widget
? toplevel_widget
->focus_manager_
.get() : NULL
;
770 const FocusManager
* Widget::GetFocusManager() const {
771 const Widget
* toplevel_widget
= GetTopLevelWidget();
772 return toplevel_widget
? toplevel_widget
->focus_manager_
.get() : NULL
;
775 ui::InputMethod
* Widget::GetInputMethod() {
776 if (is_top_level()) {
777 // Only creates the shared the input method instance on top level widget.
778 return native_widget_private()->GetInputMethod();
780 Widget
* toplevel
= GetTopLevelWidget();
781 // If GetTopLevelWidget() returns itself which is not toplevel,
782 // the widget is detached from toplevel widget.
783 // TODO(oshima): Fix GetTopLevelWidget() to return NULL
784 // if there is no toplevel. We probably need to add GetTopMostWidget()
785 // to replace some use cases.
786 return (toplevel
&& toplevel
!= this) ? toplevel
->GetInputMethod()
791 void Widget::RunShellDrag(View
* view
,
792 const ui::OSExchangeData
& data
,
793 const gfx::Point
& location
,
795 ui::DragDropTypes::DragEventSource source
) {
796 dragged_view_
= view
;
799 WidgetDeletionObserver
widget_deletion_observer(this);
800 native_widget_
->RunShellDrag(view
, data
, location
, operation
, source
);
802 // The widget may be destroyed during the drag operation.
803 if (!widget_deletion_observer
.IsWidgetAlive())
806 // If the view is removed during the drag operation, dragged_view_ is set to
808 if (view
&& dragged_view_
== view
) {
809 dragged_view_
= NULL
;
815 void Widget::SchedulePaintInRect(const gfx::Rect
& rect
) {
816 native_widget_
->SchedulePaintInRect(rect
);
819 void Widget::SetCursor(gfx::NativeCursor cursor
) {
820 native_widget_
->SetCursor(cursor
);
823 bool Widget::IsMouseEventsEnabled() const {
824 return native_widget_
->IsMouseEventsEnabled();
827 void Widget::SetNativeWindowProperty(const char* name
, void* value
) {
828 native_widget_
->SetNativeWindowProperty(name
, value
);
831 void* Widget::GetNativeWindowProperty(const char* name
) const {
832 return native_widget_
->GetNativeWindowProperty(name
);
835 void Widget::UpdateWindowTitle() {
836 if (!non_client_view_
)
839 // Update the native frame's text. We do this regardless of whether or not
840 // the native frame is being used, since this also updates the taskbar, etc.
841 base::string16 window_title
= widget_delegate_
->GetWindowTitle();
842 base::i18n::AdjustStringForLocaleDirection(&window_title
);
843 if (!native_widget_
->SetWindowTitle(window_title
))
845 non_client_view_
->UpdateWindowTitle();
847 // If the non-client view is rendering its own title, it'll need to relayout
848 // now and to get a paint update later on.
849 non_client_view_
->Layout();
852 void Widget::UpdateWindowIcon() {
853 if (non_client_view_
)
854 non_client_view_
->UpdateWindowIcon();
855 native_widget_
->SetWindowIcons(widget_delegate_
->GetWindowIcon(),
856 widget_delegate_
->GetWindowAppIcon());
859 FocusTraversable
* Widget::GetFocusTraversable() {
860 return static_cast<internal::RootView
*>(root_view_
.get());
863 void Widget::ThemeChanged() {
864 root_view_
->ThemeChanged();
867 void Widget::LocaleChanged() {
868 root_view_
->LocaleChanged();
871 void Widget::DeviceScaleFactorChanged(float device_scale_factor
) {
872 root_view_
->DeviceScaleFactorChanged(device_scale_factor
);
875 void Widget::SetFocusTraversableParent(FocusTraversable
* parent
) {
876 root_view_
->SetFocusTraversableParent(parent
);
879 void Widget::SetFocusTraversableParentView(View
* parent_view
) {
880 root_view_
->SetFocusTraversableParentView(parent_view
);
883 void Widget::ClearNativeFocus() {
884 native_widget_
->ClearNativeFocus();
887 NonClientFrameView
* Widget::CreateNonClientFrameView() {
888 NonClientFrameView
* frame_view
=
889 widget_delegate_
->CreateNonClientFrameView(this);
891 frame_view
= native_widget_
->CreateNonClientFrameView();
892 if (!frame_view
&& ViewsDelegate::GetInstance()) {
894 ViewsDelegate::GetInstance()->CreateDefaultNonClientFrameView(this);
899 CustomFrameView
* custom_frame_view
= new CustomFrameView
;
900 custom_frame_view
->Init(this);
901 return custom_frame_view
;
904 bool Widget::ShouldUseNativeFrame() const {
905 if (frame_type_
!= FRAME_TYPE_DEFAULT
)
906 return frame_type_
== FRAME_TYPE_FORCE_NATIVE
;
907 return native_widget_
->ShouldUseNativeFrame();
910 bool Widget::ShouldWindowContentsBeTransparent() const {
911 return native_widget_
->ShouldWindowContentsBeTransparent();
914 void Widget::DebugToggleFrameType() {
915 if (frame_type_
== FRAME_TYPE_DEFAULT
) {
916 frame_type_
= ShouldUseNativeFrame() ? FRAME_TYPE_FORCE_CUSTOM
:
917 FRAME_TYPE_FORCE_NATIVE
;
919 frame_type_
= frame_type_
== FRAME_TYPE_FORCE_CUSTOM
?
920 FRAME_TYPE_FORCE_NATIVE
: FRAME_TYPE_FORCE_CUSTOM
;
925 void Widget::FrameTypeChanged() {
926 native_widget_
->FrameTypeChanged();
929 const ui::Compositor
* Widget::GetCompositor() const {
930 return native_widget_
->GetCompositor();
933 const ui::Layer
* Widget::GetLayer() const {
934 return native_widget_
->GetLayer();
937 void Widget::ReorderNativeViews() {
938 native_widget_
->ReorderNativeViews();
941 void Widget::UpdateRootLayers() {
942 // Calculate the layers requires traversing the tree, and since nearly any
943 // mutation of the tree can trigger this call we delay until absolutely
945 root_layers_dirty_
= true;
948 const NativeWidget
* Widget::native_widget() const {
949 return native_widget_
;
952 NativeWidget
* Widget::native_widget() {
953 return native_widget_
;
956 void Widget::SetCapture(View
* view
) {
957 if (!native_widget_
->HasCapture()) {
958 native_widget_
->SetCapture();
960 // Early return if setting capture was unsuccessful.
961 if (!native_widget_
->HasCapture())
965 if (internal::NativeWidgetPrivate::IsMouseButtonDown())
966 is_mouse_button_pressed_
= true;
967 root_view_
->SetMouseHandler(view
);
970 void Widget::ReleaseCapture() {
971 if (native_widget_
->HasCapture())
972 native_widget_
->ReleaseCapture();
975 bool Widget::HasCapture() {
976 return native_widget_
->HasCapture();
979 TooltipManager
* Widget::GetTooltipManager() {
980 return native_widget_
->GetTooltipManager();
983 const TooltipManager
* Widget::GetTooltipManager() const {
984 return native_widget_
->GetTooltipManager();
987 gfx::Rect
Widget::GetWorkAreaBoundsInScreen() const {
988 return native_widget_
->GetWorkAreaBoundsInScreen();
991 void Widget::SynthesizeMouseMoveEvent() {
992 // In screen coordinate.
993 gfx::Point mouse_location
= EventMonitor::GetLastMouseLocation();
994 if (!GetWindowBoundsInScreen().Contains(mouse_location
))
997 // Convert: screen coordinate -> widget coordinate.
998 View::ConvertPointFromScreen(root_view_
.get(), &mouse_location
);
999 last_mouse_event_was_move_
= false;
1000 ui::MouseEvent
mouse_event(ui::ET_MOUSE_MOVED
, mouse_location
,
1001 mouse_location
, ui::EventTimeForNow(),
1002 ui::EF_IS_SYNTHESIZED
, 0);
1003 root_view_
->OnMouseMoved(mouse_event
);
1006 void Widget::OnRootViewLayout() {
1007 native_widget_
->OnRootViewLayout();
1010 bool Widget::IsTranslucentWindowOpacitySupported() const {
1011 return native_widget_
->IsTranslucentWindowOpacitySupported();
1014 void Widget::OnSizeConstraintsChanged() {
1015 native_widget_
->OnSizeConstraintsChanged();
1016 non_client_view_
->SizeConstraintsChanged();
1019 void Widget::OnOwnerClosing() {
1022 ////////////////////////////////////////////////////////////////////////////////
1023 // Widget, NativeWidgetDelegate implementation:
1025 bool Widget::IsModal() const {
1026 return widget_delegate_
->GetModalType() != ui::MODAL_TYPE_NONE
;
1029 bool Widget::IsDialogBox() const {
1030 return !!widget_delegate_
->AsDialogDelegate();
1033 bool Widget::CanActivate() const {
1034 return widget_delegate_
->CanActivate();
1037 bool Widget::IsInactiveRenderingDisabled() const {
1038 return disable_inactive_rendering_
;
1041 void Widget::EnableInactiveRendering() {
1042 SetInactiveRenderingDisabled(false);
1045 void Widget::OnNativeWidgetActivationChanged(bool active
) {
1046 // On windows we may end up here before we've completed initialization (from
1047 // an WM_NCACTIVATE). If that happens the WidgetDelegate likely doesn't know
1048 // the Widget and will crash attempting to access it.
1049 if (!active
&& native_widget_initialized_
)
1050 SaveWindowPlacement();
1052 FOR_EACH_OBSERVER(WidgetObserver
, observers_
,
1053 OnWidgetActivationChanged(this, active
));
1055 if (IsVisible() && non_client_view())
1056 non_client_view()->frame_view()->SchedulePaint();
1059 void Widget::OnNativeFocus() {
1060 WidgetFocusManager::GetInstance()->OnNativeFocusChanged(GetNativeView());
1063 void Widget::OnNativeBlur() {
1064 WidgetFocusManager::GetInstance()->OnNativeFocusChanged(nullptr);
1067 void Widget::OnNativeWidgetVisibilityChanging(bool visible
) {
1068 FOR_EACH_OBSERVER(WidgetObserver
, observers_
,
1069 OnWidgetVisibilityChanging(this, visible
));
1072 void Widget::OnNativeWidgetVisibilityChanged(bool visible
) {
1073 View
* root
= GetRootView();
1075 root
->PropagateVisibilityNotifications(root
, visible
);
1076 FOR_EACH_OBSERVER(WidgetObserver
, observers_
,
1077 OnWidgetVisibilityChanged(this, visible
));
1078 if (GetCompositor() && root
&& root
->layer())
1079 root
->layer()->SetVisible(visible
);
1082 void Widget::OnNativeWidgetCreated(bool desktop_widget
) {
1084 focus_manager_
.reset(FocusManagerFactory::Create(this, desktop_widget
));
1086 native_widget_
->InitModalType(widget_delegate_
->GetModalType());
1088 FOR_EACH_OBSERVER(WidgetObserver
, observers_
, OnWidgetCreated(this));
1091 void Widget::OnNativeWidgetDestroying() {
1092 // Tell the focus manager (if any) that root_view is being removed
1093 // in case that the focused view is under this root view.
1094 if (GetFocusManager())
1095 GetFocusManager()->ViewRemoved(root_view_
.get());
1096 FOR_EACH_OBSERVER(WidgetObserver
, observers_
, OnWidgetDestroying(this));
1097 if (non_client_view_
)
1098 non_client_view_
->WindowClosing();
1099 widget_delegate_
->WindowClosing();
1102 void Widget::OnNativeWidgetDestroyed() {
1103 FOR_EACH_OBSERVER(WidgetObserver
, observers_
, OnWidgetDestroyed(this));
1104 widget_delegate_
->DeleteDelegate();
1105 widget_delegate_
= NULL
;
1106 native_widget_destroyed_
= true;
1109 gfx::Size
Widget::GetMinimumSize() const {
1110 return non_client_view_
? non_client_view_
->GetMinimumSize() : gfx::Size();
1113 gfx::Size
Widget::GetMaximumSize() const {
1114 return non_client_view_
? non_client_view_
->GetMaximumSize() : gfx::Size();
1117 void Widget::OnNativeWidgetMove() {
1118 widget_delegate_
->OnWidgetMove();
1119 NotifyCaretBoundsChanged(GetInputMethod());
1121 FOR_EACH_OBSERVER(WidgetObserver
, observers_
, OnWidgetBoundsChanged(
1123 GetWindowBoundsInScreen()));
1126 void Widget::OnNativeWidgetSizeChanged(const gfx::Size
& new_size
) {
1127 View
* root
= GetRootView();
1129 root
->SetSize(new_size
);
1131 NotifyCaretBoundsChanged(GetInputMethod());
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 void Widget::OnNativeWidgetPaint(const ui::PaintContext
& context
) {
1156 // On Linux Aura, we can get here during Init() because of the
1157 // SetInitialBounds call.
1158 if (!native_widget_initialized_
)
1160 GetRootView()->Paint(context
);
1163 int Widget::GetNonClientComponent(const gfx::Point
& point
) {
1164 int component
= non_client_view_
?
1165 non_client_view_
->NonClientHitTest(point
) :
1168 if (movement_disabled_
&& (component
== HTCAPTION
|| component
== HTSYSMENU
))
1174 void Widget::OnKeyEvent(ui::KeyEvent
* event
) {
1175 SendEventToProcessor(event
);
1178 // TODO(tdanderson): We should not be calling the OnMouse*() functions on
1179 // RootView from anywhere in Widget. Use
1180 // SendEventToProcessor() instead. See crbug.com/348087.
1181 void Widget::OnMouseEvent(ui::MouseEvent
* event
) {
1182 View
* root_view
= GetRootView();
1183 switch (event
->type()) {
1184 case ui::ET_MOUSE_PRESSED
: {
1185 last_mouse_event_was_move_
= false;
1187 // We may get deleted by the time we return from OnMousePressed. So we
1188 // use an observer to make sure we are still alive.
1189 WidgetDeletionObserver
widget_deletion_observer(this);
1191 // Make sure we're still visible before we attempt capture as the mouse
1192 // press processing may have made the window hide (as happens with menus).
1194 // It is possible for a View to show a context menu on mouse-press. Since
1195 // the menu does a capture and starts a nested message-loop, the release
1196 // would go to the menu. The next click (i.e. both mouse-press and release
1197 // events) also go to the menu. The menu (and the nested message-loop)
1198 // gets closed after this second release event. The code then resumes from
1199 // here. So make sure that the mouse-button is still down before doing a
1201 if (root_view
&& root_view
->OnMousePressed(*event
) &&
1202 widget_deletion_observer
.IsWidgetAlive() && IsVisible() &&
1203 internal::NativeWidgetPrivate::IsMouseButtonDown()) {
1204 is_mouse_button_pressed_
= true;
1205 if (!native_widget_
->HasCapture())
1206 native_widget_
->SetCapture();
1207 event
->SetHandled();
1212 case ui::ET_MOUSE_RELEASED
:
1213 last_mouse_event_was_move_
= false;
1214 is_mouse_button_pressed_
= false;
1215 // Release capture first, to avoid confusion if OnMouseReleased blocks.
1216 if (auto_release_capture_
&& native_widget_
->HasCapture()) {
1217 base::AutoReset
<bool> resetter(&ignore_capture_loss_
, true);
1218 native_widget_
->ReleaseCapture();
1221 root_view
->OnMouseReleased(*event
);
1222 if ((event
->flags() & ui::EF_IS_NON_CLIENT
) == 0)
1223 event
->SetHandled();
1226 case ui::ET_MOUSE_MOVED
:
1227 case ui::ET_MOUSE_DRAGGED
:
1228 if (native_widget_
->HasCapture() && is_mouse_button_pressed_
) {
1229 last_mouse_event_was_move_
= false;
1231 root_view
->OnMouseDragged(*event
);
1232 } else if (!last_mouse_event_was_move_
||
1233 last_mouse_event_position_
!= event
->location()) {
1234 last_mouse_event_position_
= event
->location();
1235 last_mouse_event_was_move_
= true;
1237 root_view
->OnMouseMoved(*event
);
1241 case ui::ET_MOUSE_EXITED
:
1242 last_mouse_event_was_move_
= false;
1244 root_view
->OnMouseExited(*event
);
1247 case ui::ET_MOUSEWHEEL
:
1248 if (root_view
&& root_view
->OnMouseWheel(
1249 static_cast<const ui::MouseWheelEvent
&>(*event
)))
1250 event
->SetHandled();
1258 void Widget::OnMouseCaptureLost() {
1259 if (ignore_capture_loss_
)
1262 View
* root_view
= GetRootView();
1264 root_view
->OnMouseCaptureLost();
1265 is_mouse_button_pressed_
= false;
1268 void Widget::OnScrollEvent(ui::ScrollEvent
* event
) {
1269 ui::ScrollEvent
event_copy(*event
);
1270 SendEventToProcessor(&event_copy
);
1272 // Convert unhandled ui::ET_SCROLL events into ui::ET_MOUSEWHEEL events.
1273 if (!event_copy
.handled() && event_copy
.type() == ui::ET_SCROLL
) {
1274 ui::MouseWheelEvent
wheel(*event
);
1275 OnMouseEvent(&wheel
);
1279 void Widget::OnGestureEvent(ui::GestureEvent
* event
) {
1280 // We explicitly do not capture here. Not capturing enables multiple widgets
1281 // to get tap events at the same time. Views (such as tab dragging) may
1282 // explicitly capture.
1283 SendEventToProcessor(event
);
1286 bool Widget::ExecuteCommand(int command_id
) {
1287 return widget_delegate_
->ExecuteWindowsCommand(command_id
);
1290 const std::vector
<ui::Layer
*>& Widget::GetRootLayers() {
1291 if (root_layers_dirty_
) {
1292 root_layers_dirty_
= false;
1293 root_layers_
.clear();
1294 BuildRootLayers(GetRootView(), &root_layers_
);
1296 return root_layers_
;
1299 bool Widget::HasHitTestMask() const {
1300 return widget_delegate_
->WidgetHasHitTestMask();
1303 void Widget::GetHitTestMask(gfx::Path
* mask
) const {
1305 widget_delegate_
->GetWidgetHitTestMask(mask
);
1308 Widget
* Widget::AsWidget() {
1312 const Widget
* Widget::AsWidget() const {
1316 bool Widget::SetInitialFocus(ui::WindowShowState show_state
) {
1317 View
* v
= widget_delegate_
->GetInitiallyFocusedView();
1318 if (!focus_on_creation_
|| show_state
== ui::SHOW_STATE_INACTIVE
||
1319 show_state
== ui::SHOW_STATE_MINIMIZED
) {
1320 // If not focusing the window now, tell the focus manager which view to
1321 // focus when the window is restored.
1323 focus_manager_
->SetStoredFocusView(v
);
1331 ////////////////////////////////////////////////////////////////////////////////
1332 // Widget, ui::EventSource implementation:
1333 ui::EventProcessor
* Widget::GetEventProcessor() {
1334 return root_view_
.get();
1337 ////////////////////////////////////////////////////////////////////////////////
1338 // Widget, FocusTraversable implementation:
1340 FocusSearch
* Widget::GetFocusSearch() {
1341 return root_view_
->GetFocusSearch();
1344 FocusTraversable
* Widget::GetFocusTraversableParent() {
1345 // We are a proxy to the root view, so we should be bypassed when traversing
1346 // up and as a result this should not be called.
1351 View
* Widget::GetFocusTraversableParentView() {
1352 // We are a proxy to the root view, so we should be bypassed when traversing
1353 // up and as a result this should not be called.
1358 ////////////////////////////////////////////////////////////////////////////////
1359 // Widget, ui::NativeThemeObserver implementation:
1361 void Widget::OnNativeThemeUpdated(ui::NativeTheme
* observed_theme
) {
1362 DCHECK(observer_manager_
.IsObserving(observed_theme
));
1364 ui::NativeTheme
* current_native_theme
= GetNativeTheme();
1365 if (!observer_manager_
.IsObserving(current_native_theme
)) {
1366 observer_manager_
.RemoveAll();
1367 observer_manager_
.Add(current_native_theme
);
1370 root_view_
->PropagateNativeThemeChanged(current_native_theme
);
1373 ////////////////////////////////////////////////////////////////////////////////
1374 // Widget, protected:
1376 internal::RootView
* Widget::CreateRootView() {
1377 return new internal::RootView(this);
1380 void Widget::DestroyRootView() {
1381 non_client_view_
= NULL
;
1385 void Widget::OnDragWillStart() {
1388 void Widget::OnDragComplete() {
1391 ////////////////////////////////////////////////////////////////////////////////
1394 void Widget::SetInactiveRenderingDisabled(bool value
) {
1395 if (value
== disable_inactive_rendering_
)
1398 disable_inactive_rendering_
= value
;
1399 if (non_client_view_
)
1400 non_client_view_
->SetInactiveRenderingDisabled(value
);
1403 void Widget::SaveWindowPlacement() {
1404 // The window delegate does the actual saving for us. It seems like (judging
1405 // by go/crash) that in some circumstances we can end up here after
1406 // WM_DESTROY, at which point the window delegate is likely gone. So just
1408 if (!widget_delegate_
)
1411 ui::WindowShowState show_state
= ui::SHOW_STATE_NORMAL
;
1413 native_widget_
->GetWindowPlacement(&bounds
, &show_state
);
1414 widget_delegate_
->SaveWindowPlacement(bounds
, show_state
);
1417 void Widget::SaveWindowPlacementIfInitialized() {
1418 if (native_widget_initialized_
)
1419 SaveWindowPlacement();
1422 void Widget::SetInitialBounds(const gfx::Rect
& bounds
) {
1423 if (!non_client_view_
)
1426 gfx::Rect saved_bounds
;
1427 if (GetSavedWindowPlacement(&saved_bounds
, &saved_show_state_
)) {
1428 if (saved_show_state_
== ui::SHOW_STATE_MAXIMIZED
) {
1429 // If we're going to maximize, wait until Show is invoked to set the
1430 // bounds. That way we avoid a noticeable resize.
1431 initial_restored_bounds_
= saved_bounds
;
1432 } else if (!saved_bounds
.IsEmpty()) {
1433 // If the saved bounds are valid, use them.
1434 SetBounds(saved_bounds
);
1437 if (bounds
.IsEmpty()) {
1438 // No initial bounds supplied, so size the window to its content and
1439 // center over its parent.
1440 native_widget_
->CenterWindow(non_client_view_
->GetPreferredSize());
1442 // Use the supplied initial bounds.
1443 SetBoundsConstrained(bounds
);
1448 void Widget::SetInitialBoundsForFramelessWindow(const gfx::Rect
& bounds
) {
1449 if (bounds
.IsEmpty()) {
1450 View
* contents_view
= GetContentsView();
1451 DCHECK(contents_view
);
1452 // No initial bounds supplied, so size the window to its content and
1453 // center over its parent if preferred size is provided.
1454 gfx::Size size
= contents_view
->GetPreferredSize();
1455 if (!size
.IsEmpty())
1456 native_widget_
->CenterWindow(size
);
1458 // Use the supplied initial bounds.
1459 SetBoundsConstrained(bounds
);
1463 bool Widget::GetSavedWindowPlacement(gfx::Rect
* bounds
,
1464 ui::WindowShowState
* show_state
) {
1465 // First we obtain the window's saved show-style and store it. We need to do
1466 // this here, rather than in Show() because by the time Show() is called,
1467 // the window's size will have been reset (below) and the saved maximized
1468 // state will have been lost. Sadly there's no way to tell on Windows when
1469 // a window is restored from maximized state, so we can't more accurately
1470 // track maximized state independently of sizing information.
1472 // Restore the window's placement from the controller.
1473 if (widget_delegate_
->GetSavedWindowPlacement(this, bounds
, show_state
)) {
1474 if (!widget_delegate_
->ShouldRestoreWindowSize()) {
1475 bounds
->set_size(non_client_view_
->GetPreferredSize());
1477 gfx::Size minimum_size
= GetMinimumSize();
1478 // Make sure the bounds are at least the minimum size.
1479 if (bounds
->width() < minimum_size
.width())
1480 bounds
->set_width(minimum_size
.width());
1482 if (bounds
->height() < minimum_size
.height())
1483 bounds
->set_height(minimum_size
.height());
1490 namespace internal
{
1492 ////////////////////////////////////////////////////////////////////////////////
1493 // internal::NativeWidgetPrivate, NativeWidget implementation:
1495 internal::NativeWidgetPrivate
* NativeWidgetPrivate::AsNativeWidgetPrivate() {
1499 } // namespace internal
1500 } // namespace views