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

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

Issue 7129022: Move last of event handlers down to NativeWidgetWin/Gtk. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "views/widget/widget.h" 5 #include "views/widget/widget.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "ui/base/l10n/l10n_font_util.h"
11 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/gfx/compositor/compositor.h" 12 #include "ui/gfx/compositor/compositor.h"
11 #include "views/focus/view_storage.h" 13 #include "views/focus/view_storage.h"
12 #include "views/ime/input_method.h" 14 #include "views/ime/input_method.h"
13 #include "views/views_delegate.h" 15 #include "views/views_delegate.h"
14 #include "views/widget/default_theme_provider.h" 16 #include "views/widget/default_theme_provider.h"
15 #include "views/widget/root_view.h" 17 #include "views/widget/root_view.h"
16 #include "views/widget/native_widget.h" 18 #include "views/widget/native_widget.h"
17 #include "views/widget/widget_delegate.h" 19 #include "views/widget/widget_delegate.h"
18 #include "views/window/custom_frame_view.h" 20 #include "views/window/custom_frame_view.h"
19 21
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 : is_mouse_button_pressed_(false), 93 : is_mouse_button_pressed_(false),
92 last_mouse_event_was_move_(false), 94 last_mouse_event_was_move_(false),
93 native_widget_(NULL), 95 native_widget_(NULL),
94 widget_delegate_(NULL), 96 widget_delegate_(NULL),
95 non_client_view_(NULL), 97 non_client_view_(NULL),
96 dragged_view_(NULL), 98 dragged_view_(NULL),
97 ownership_(InitParams::NATIVE_WIDGET_OWNS_WIDGET), 99 ownership_(InitParams::NATIVE_WIDGET_OWNS_WIDGET),
98 is_secondary_widget_(true), 100 is_secondary_widget_(true),
99 frame_type_(FRAME_TYPE_DEFAULT), 101 frame_type_(FRAME_TYPE_DEFAULT),
100 disable_inactive_rendering_(false), 102 disable_inactive_rendering_(false),
101 widget_closed_(false) { 103 widget_closed_(false),
104 saved_maximized_state_(false),
105 minimum_size_(100, 100) {
102 } 106 }
103 107
104 Widget::~Widget() { 108 Widget::~Widget() {
105 DestroyRootView(); 109 DestroyRootView();
106 110
107 if (ownership_ == InitParams::WIDGET_OWNS_NATIVE_WIDGET) 111 if (ownership_ == InitParams::WIDGET_OWNS_NATIVE_WIDGET)
108 delete native_widget_; 112 delete native_widget_;
109 } 113 }
110 114
111 // static 115 // static
112 void Widget::SetPureViews(bool pure) { 116 void Widget::SetPureViews(bool pure) {
113 use_pure_views = pure; 117 use_pure_views = pure;
114 } 118 }
115 119
116 // static 120 // static
117 bool Widget::IsPureViews() { 121 bool Widget::IsPureViews() {
118 return use_pure_views; 122 return use_pure_views;
119 } 123 }
120 124
121 // static 125 // static
122 Widget* Widget::GetWidgetForNativeView(gfx::NativeView native_view) { 126 Widget* Widget::GetWidgetForNativeView(gfx::NativeView native_view) {
123 NativeWidget* native_widget = 127 NativeWidget* native_widget =
124 NativeWidget::GetNativeWidgetForNativeView(native_view); 128 NativeWidget::GetNativeWidgetForNativeView(native_view);
125 return native_widget ? native_widget->GetWidget() : NULL; 129 return native_widget ? native_widget->GetWidget() : NULL;
126 } 130 }
127 131
132 // static
133 int Widget::GetLocalizedContentsWidth(int col_resource_id) {
134 return ui::GetLocalizedContentsWidthForFont(col_resource_id,
135 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
136 }
137
138 // static
139 int Widget::GetLocalizedContentsHeight(int row_resource_id) {
140 return ui::GetLocalizedContentsHeightForFont(row_resource_id,
141 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
142 }
143
144 // static
145 gfx::Size Widget::GetLocalizedContentsSize(int col_resource_id,
146 int row_resource_id) {
147 return gfx::Size(GetLocalizedContentsWidth(col_resource_id),
148 GetLocalizedContentsHeight(row_resource_id));
149 }
150
128 void Widget::Init(const InitParams& params) { 151 void Widget::Init(const InitParams& params) {
129 widget_delegate_ = 152 widget_delegate_ =
130 params.delegate ? params.delegate : new DefaultWidgetDelegate; 153 params.delegate ? params.delegate : new DefaultWidgetDelegate;
131 ownership_ = params.ownership; 154 ownership_ = params.ownership;
132 native_widget_ = 155 native_widget_ =
133 params.native_widget ? params.native_widget 156 params.native_widget ? params.native_widget
134 : NativeWidget::CreateNativeWidget(this); 157 : NativeWidget::CreateNativeWidget(this);
135 GetRootView(); 158 GetRootView();
136 default_theme_provider_.reset(new DefaultThemeProvider); 159 default_theme_provider_.reset(new DefaultThemeProvider);
137 if (params.type == InitParams::TYPE_MENU) 160 if (params.type == InitParams::TYPE_MENU)
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 void Widget::CloseNow() { 300 void Widget::CloseNow() {
278 native_widget_->CloseNow(); 301 native_widget_->CloseNow();
279 } 302 }
280 303
281 void Widget::EnableClose(bool enable) { 304 void Widget::EnableClose(bool enable) {
282 non_client_view_->EnableClose(enable); 305 non_client_view_->EnableClose(enable);
283 native_widget_->EnableClose(enable); 306 native_widget_->EnableClose(enable);
284 } 307 }
285 308
286 void Widget::Show() { 309 void Widget::Show() {
287 native_widget_->Show(); 310 if (non_client_view_) {
311 native_widget_->ShowNativeWidget(
312 saved_maximized_state_ ? NativeWidget::SHOW_MAXIMIZED
313 : NativeWidget::SHOW_RESTORED);
314 // |saved_maximized_state_| only applies the first time the window is shown.
315 // If we don't reset the value the window will be shown maximized every time
316 // it is subsequently shown after being hidden.
317 saved_maximized_state_ = false;
318 } else {
319 native_widget_->Show();
320 }
288 } 321 }
289 322
290 void Widget::Hide() { 323 void Widget::Hide() {
291 native_widget_->Hide(); 324 native_widget_->Hide();
292 } 325 }
293 326
294 void Widget::ShowInactive() { 327 void Widget::ShowInactive() {
295 native_widget_->ShowNativeWidget(NativeWidget::SHOW_INACTIVE); 328 native_widget_->ShowNativeWidget(NativeWidget::SHOW_INACTIVE);
296 } 329 }
297 330
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 if (ViewsDelegate::views_delegate) 550 if (ViewsDelegate::views_delegate)
518 ViewsDelegate::views_delegate->NotifyAccessibilityEvent(view, event_type); 551 ViewsDelegate::views_delegate->NotifyAccessibilityEvent(view, event_type);
519 552
520 if (send_native_event) 553 if (send_native_event)
521 native_widget_->SendNativeAccessibilityEvent(view, event_type); 554 native_widget_->SendNativeAccessibilityEvent(view, event_type);
522 } 555 }
523 556
524 //////////////////////////////////////////////////////////////////////////////// 557 ////////////////////////////////////////////////////////////////////////////////
525 // Widget, NativeWidgetDelegate implementation: 558 // Widget, NativeWidgetDelegate implementation:
526 559
560 bool Widget::IsModal() const {
561 return widget_delegate_->IsModal();
562 }
563
564 bool Widget::IsDialogBox() const {
565 return !!widget_delegate_->AsDialogDelegate();
566 }
567
527 bool Widget::CanActivate() const { 568 bool Widget::CanActivate() const {
528 return widget_delegate_->CanActivate(); 569 return widget_delegate_->CanActivate();
529 } 570 }
530 571
531 bool Widget::IsInactiveRenderingDisabled() const { 572 bool Widget::IsInactiveRenderingDisabled() const {
532 return disable_inactive_rendering_; 573 return disable_inactive_rendering_;
533 } 574 }
534 575
535 void Widget::EnableInactiveRendering() { 576 void Widget::EnableInactiveRendering() {
536 disable_inactive_rendering_ = false; 577 disable_inactive_rendering_ = false;
(...skipping 14 matching lines...) Expand all
551 focused_view, 592 focused_view,
552 GetNativeView()); 593 GetNativeView());
553 } 594 }
554 595
555 void Widget::OnNativeBlur(gfx::NativeView focused_view) { 596 void Widget::OnNativeBlur(gfx::NativeView focused_view) {
556 GetFocusManager()->GetWidgetFocusManager()->OnWidgetFocusEvent( 597 GetFocusManager()->GetWidgetFocusManager()->OnWidgetFocusEvent(
557 GetNativeView(), 598 GetNativeView(),
558 focused_view); 599 focused_view);
559 } 600 }
560 601
561 void Widget::OnNativeWidgetCreated() { 602 void Widget::OnNativeWidgetCreated(const gfx::Rect& create_bounds) {
562 if (GetTopLevelWidget() == this) { 603 if (GetTopLevelWidget() == this) {
563 // Only the top level Widget in a native widget hierarchy has a focus 604 // Only the top level Widget in a native widget hierarchy has a focus
564 // manager. 605 // manager.
565 focus_manager_.reset(new FocusManager(this)); 606 focus_manager_.reset(new FocusManager(this));
566 } 607 }
567 EnsureCompositor(); 608 EnsureCompositor();
568 609
569 native_widget_->SetAccessibleRole( 610 native_widget_->SetAccessibleRole(
570 widget_delegate_->GetAccessibleWindowRole()); 611 widget_delegate_->GetAccessibleWindowRole());
571 native_widget_->SetAccessibleState( 612 native_widget_->SetAccessibleState(
572 widget_delegate_->GetAccessibleWindowState()); 613 widget_delegate_->GetAccessibleWindowState());
614
615 if (widget_delegate_->IsModal())
616 native_widget_->BecomeModal();
617
618 UpdateWindowTitle();
619 SetInitialBounds(create_bounds);
573 } 620 }
574 621
575 void Widget::OnNativeWidgetDestroying() { 622 void Widget::OnNativeWidgetDestroying() {
576 if (non_client_view_) 623 if (non_client_view_)
577 non_client_view_->WindowClosing(); 624 non_client_view_->WindowClosing();
578 widget_delegate_->WindowClosing(); 625 widget_delegate_->WindowClosing();
579 } 626 }
580 627
581 void Widget::OnNativeWidgetDestroyed() { 628 void Widget::OnNativeWidgetDestroyed() {
582 widget_delegate_->DeleteDelegate(); 629 widget_delegate_->DeleteDelegate();
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 // bail. 819 // bail.
773 if (!widget_delegate_) 820 if (!widget_delegate_)
774 return; 821 return;
775 822
776 bool maximized; 823 bool maximized;
777 gfx::Rect bounds; 824 gfx::Rect bounds;
778 native_widget_->GetWindowBoundsAndMaximizedState(&bounds, &maximized); 825 native_widget_->GetWindowBoundsAndMaximizedState(&bounds, &maximized);
779 widget_delegate_->SaveWindowPlacement(bounds, maximized); 826 widget_delegate_->SaveWindowPlacement(bounds, maximized);
780 } 827 }
781 828
829 void Widget::SetInitialBounds(const gfx::Rect& bounds) {
830 if (!non_client_view_)
831 return;
832
833 // First we obtain the window's saved show-style and store it. We need to do
834 // this here, rather than in Show() because by the time Show() is called,
835 // the window's size will have been reset (below) and the saved maximized
836 // state will have been lost. Sadly there's no way to tell on Windows when
837 // a window is restored from maximized state, so we can't more accurately
838 // track maximized state independently of sizing information.
839 widget_delegate_->GetSavedMaximizedState(
840 &saved_maximized_state_);
841
842 // Restore the window's placement from the controller.
843 gfx::Rect saved_bounds = bounds;
844 if (widget_delegate_->GetSavedWindowBounds(&saved_bounds)) {
845 if (!widget_delegate_->ShouldRestoreWindowSize()) {
846 saved_bounds.set_size(non_client_view_->GetPreferredSize());
847 } else {
848 // Make sure the bounds are at least the minimum size.
849 if (saved_bounds.width() < minimum_size_.width()) {
850 saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(),
851 saved_bounds.right() + minimum_size_.width() -
852 saved_bounds.width(),
853 saved_bounds.bottom());
854 }
855
856 if (saved_bounds.height() < minimum_size_.height()) {
857 saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(),
858 saved_bounds.right(),
859 saved_bounds.bottom() + minimum_size_.height() -
860 saved_bounds.height());
861 }
862 }
863
864 // Widget's SetBounds method does not further modify the bounds that are
865 // passed to it.
866 SetBounds(saved_bounds);
867 } else {
868 if (bounds.IsEmpty()) {
869 // No initial bounds supplied, so size the window to its content and
870 // center over its parent.
871 native_widget_->CenterWindow(non_client_view_->GetPreferredSize());
872 } else {
873 // Use the supplied initial bounds.
874 SetBoundsConstrained(bounds, NULL);
875 }
876 }
877 }
782 878
783 879
784 } // namespace views 880 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698