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

Side by Side Diff: views/window/window.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
« no previous file with comments | « views/window/window.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/window/window.h" 5 #include "views/window/window.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "third_party/skia/include/core/SkBitmap.h" 8 #include "third_party/skia/include/core/SkBitmap.h"
9 #include "ui/base/l10n/l10n_font_util.h"
10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/font.h" 9 #include "ui/gfx/font.h"
12 #include "ui/gfx/rect.h" 10 #include "ui/gfx/rect.h"
13 #include "ui/gfx/size.h" 11 #include "ui/gfx/size.h"
14 #include "views/widget/widget.h" 12 #include "views/widget/widget.h"
15 #include "views/widget/native_widget.h" 13 #include "views/widget/native_widget.h"
16 #include "views/window/native_window.h" 14 #include "views/window/native_window.h"
17 #include "views/window/window_delegate.h" 15 #include "views/window/window_delegate.h"
18 16
19 namespace views { 17 namespace views {
20 18
21 //////////////////////////////////////////////////////////////////////////////// 19 ////////////////////////////////////////////////////////////////////////////////
22 // Window, public: 20 // Window, public:
23 21
24 Window::InitParams::InitParams(WindowDelegate* window_delegate) 22 Window::InitParams::InitParams(WindowDelegate* window_delegate)
25 : window_delegate(window_delegate), 23 : window_delegate(window_delegate),
26 parent_window(NULL), 24 parent_window(NULL),
27 native_window(NULL), 25 native_window(NULL),
28 widget_init_params(Widget::InitParams::TYPE_WINDOW) { 26 widget_init_params(Widget::InitParams::TYPE_WINDOW) {
29 } 27 }
30 28
31 Window::Window() 29 Window::Window()
32 : native_window_(NULL), 30 : native_window_(NULL) {
33 saved_maximized_state_(false),
34 minimum_size_(100, 100) {
35 } 31 }
36 32
37 Window::~Window() { 33 Window::~Window() {
38 } 34 }
39 35
40 // static 36 // static
41 Window* Window::CreateChromeWindow(gfx::NativeWindow parent, 37 Window* Window::CreateChromeWindow(gfx::NativeWindow parent,
42 const gfx::Rect& bounds, 38 const gfx::Rect& bounds,
43 WindowDelegate* window_delegate) { 39 WindowDelegate* window_delegate) {
44 Window* window = new Window; 40 Window* window = new Window;
45 Window::InitParams params(window_delegate); 41 Window::InitParams params(window_delegate);
46 params.parent_window = parent; 42 params.parent_window = parent;
47 #if defined(OS_WIN) 43 #if defined(OS_WIN)
48 params.widget_init_params.parent = parent; 44 params.widget_init_params.parent = parent;
49 #endif 45 #endif
50 params.widget_init_params.bounds = bounds; 46 params.widget_init_params.bounds = bounds;
51 window->InitWindow(params); 47 window->InitWindow(params);
52 return window; 48 return window;
53 } 49 }
54 50
55 // static
56 int Window::GetLocalizedContentsWidth(int col_resource_id) {
57 return ui::GetLocalizedContentsWidthForFont(col_resource_id,
58 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
59 }
60
61 // static
62 int Window::GetLocalizedContentsHeight(int row_resource_id) {
63 return ui::GetLocalizedContentsHeightForFont(row_resource_id,
64 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
65 }
66
67 // static
68 gfx::Size Window::GetLocalizedContentsSize(int col_resource_id,
69 int row_resource_id) {
70 return gfx::Size(GetLocalizedContentsWidth(col_resource_id),
71 GetLocalizedContentsHeight(row_resource_id));
72 }
73
74 void Window::InitWindow(const InitParams& params) { 51 void Window::InitWindow(const InitParams& params) {
75 native_window_ = 52 native_window_ =
76 params.native_window ? params.native_window 53 params.native_window ? params.native_window
77 : NativeWindow::CreateNativeWindow(this); 54 : NativeWindow::CreateNativeWindow(this);
78 InitParams modified_params = params; 55 InitParams modified_params = params;
79 modified_params.widget_init_params.delegate = params.window_delegate; 56 modified_params.widget_init_params.delegate = params.window_delegate;
80 DCHECK(!modified_params.widget_init_params.delegate->window_); 57 DCHECK(!modified_params.widget_init_params.delegate->window_);
81 modified_params.widget_init_params.delegate->window_ = this; 58 modified_params.widget_init_params.delegate->window_ = this;
82 modified_params.widget_init_params.native_widget = 59 modified_params.widget_init_params.native_widget =
83 native_window_->AsNativeWidget(); 60 native_window_->AsNativeWidget();
84 Init(modified_params.widget_init_params); 61 Init(modified_params.widget_init_params);
85 OnNativeWindowCreated(modified_params.widget_init_params.bounds);
86 } 62 }
87 63
88 //////////////////////////////////////////////////////////////////////////////// 64 ////////////////////////////////////////////////////////////////////////////////
89 // Window, Widget overrides: 65 // Window, Widget overrides:
90 66
91 void Window::Show() {
92 native_window_->AsNativeWidget()->ShowNativeWidget(
93 saved_maximized_state_ ? NativeWidget::SHOW_MAXIMIZED
94 : NativeWidget::SHOW_RESTORED);
95 // |saved_maximized_state_| only applies the first time the window is shown.
96 // If we don't reset the value the window will be shown maximized every time
97 // it is subsequently shown after being hidden.
98 saved_maximized_state_ = false;
99 }
100
101 Window* Window::AsWindow() { 67 Window* Window::AsWindow() {
102 return this; 68 return this;
103 } 69 }
104 70
105 const Window* Window::AsWindow() const { 71 const Window* Window::AsWindow() const {
106 return this; 72 return this;
107 } 73 }
108 74
109 //////////////////////////////////////////////////////////////////////////////// 75 ////////////////////////////////////////////////////////////////////////////////
110 // Window, internal::NativeWindowDelegate implementation: 76 // Window, internal::NativeWindowDelegate implementation:
111 77
112 bool Window::IsModal() const {
113 return widget_delegate()->IsModal();
114 }
115
116 bool Window::IsDialogBox() const {
117 return !!widget_delegate()->AsDialogDelegate();
118 }
119
120 void Window::OnNativeWindowCreated(const gfx::Rect& bounds) {
121 if (widget_delegate()->IsModal())
122 native_window_->BecomeModal();
123
124 UpdateWindowTitle();
125 SetInitialBounds(bounds);
126 }
127
128 internal::NativeWidgetDelegate* Window::AsNativeWidgetDelegate() { 78 internal::NativeWidgetDelegate* Window::AsNativeWidgetDelegate() {
129 return this; 79 return this;
130 } 80 }
131 81
132 ////////////////////////////////////////////////////////////////////////////////
133 // Window, private:
134
135 void Window::SetInitialBounds(const gfx::Rect& bounds) {
136 // First we obtain the window's saved show-style and store it. We need to do
137 // this here, rather than in Show() because by the time Show() is called,
138 // the window's size will have been reset (below) and the saved maximized
139 // state will have been lost. Sadly there's no way to tell on Windows when
140 // a window is restored from maximized state, so we can't more accurately
141 // track maximized state independently of sizing information.
142 widget_delegate()->GetSavedMaximizedState(
143 &saved_maximized_state_);
144
145 // Restore the window's placement from the controller.
146 gfx::Rect saved_bounds = bounds;
147 if (widget_delegate()->GetSavedWindowBounds(&saved_bounds)) {
148 if (!widget_delegate()->ShouldRestoreWindowSize()) {
149 saved_bounds.set_size(non_client_view()->GetPreferredSize());
150 } else {
151 // Make sure the bounds are at least the minimum size.
152 if (saved_bounds.width() < minimum_size_.width()) {
153 saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(),
154 saved_bounds.right() + minimum_size_.width() -
155 saved_bounds.width(),
156 saved_bounds.bottom());
157 }
158
159 if (saved_bounds.height() < minimum_size_.height()) {
160 saved_bounds.SetRect(saved_bounds.x(), saved_bounds.y(),
161 saved_bounds.right(),
162 saved_bounds.bottom() + minimum_size_.height() -
163 saved_bounds.height());
164 }
165 }
166
167 // Widget's SetBounds method does not further modify the bounds that are
168 // passed to it.
169 SetBounds(saved_bounds);
170 } else {
171 if (bounds.IsEmpty()) {
172 // No initial bounds supplied, so size the window to its content and
173 // center over its parent.
174 native_window_->AsNativeWidget()->CenterWindow(
175 non_client_view()->GetPreferredSize());
176 } else {
177 // Use the supplied initial bounds.
178 SetBoundsConstrained(bounds, NULL);
179 }
180 }
181 }
182
183 } // namespace views 82 } // namespace views
OLDNEW
« no previous file with comments | « views/window/window.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698