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

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

Issue 7015051: Re-land: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 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') | views/window/window_gtk.h » ('j') | 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 "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "third_party/skia/include/core/SkBitmap.h" 9 #include "third_party/skia/include/core/SkBitmap.h"
10 #include "ui/base/l10n/l10n_font_util.h" 10 #include "ui/base/l10n/l10n_font_util.h"
(...skipping 29 matching lines...) Expand all
40 window_closed_(false) { 40 window_closed_(false) {
41 } 41 }
42 42
43 Window::~Window() { 43 Window::~Window() {
44 } 44 }
45 45
46 // static 46 // static
47 Window* Window::CreateChromeWindow(gfx::NativeWindow parent, 47 Window* Window::CreateChromeWindow(gfx::NativeWindow parent,
48 const gfx::Rect& bounds, 48 const gfx::Rect& bounds,
49 WindowDelegate* window_delegate) { 49 WindowDelegate* window_delegate) {
50 Window* window = NativeWindow::CreateNativeWindow(); 50 Window* window = new Window;
51 Window::InitParams params(window_delegate); 51 Window::InitParams params(window_delegate);
52 params.parent_window = parent; 52 params.parent_window = parent;
53 params.widget_init_params.bounds = bounds; 53 params.widget_init_params.bounds = bounds;
54 window->InitWindow(params); 54 window->InitWindow(params);
55 return window; 55 return window;
56 } 56 }
57 57
58 // static 58 // static
59 int Window::GetLocalizedContentsWidth(int col_resource_id) { 59 int Window::GetLocalizedContentsWidth(int col_resource_id) {
60 return ui::GetLocalizedContentsWidthForFont(col_resource_id, 60 return ui::GetLocalizedContentsWidthForFont(col_resource_id,
61 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont)); 61 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
62 } 62 }
63 63
64 // static 64 // static
65 int Window::GetLocalizedContentsHeight(int row_resource_id) { 65 int Window::GetLocalizedContentsHeight(int row_resource_id) {
66 return ui::GetLocalizedContentsHeightForFont(row_resource_id, 66 return ui::GetLocalizedContentsHeightForFont(row_resource_id,
67 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont)); 67 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
68 } 68 }
69 69
70 // static 70 // static
71 gfx::Size Window::GetLocalizedContentsSize(int col_resource_id, 71 gfx::Size Window::GetLocalizedContentsSize(int col_resource_id,
72 int row_resource_id) { 72 int row_resource_id) {
73 return gfx::Size(GetLocalizedContentsWidth(col_resource_id), 73 return gfx::Size(GetLocalizedContentsWidth(col_resource_id),
74 GetLocalizedContentsHeight(row_resource_id)); 74 GetLocalizedContentsHeight(row_resource_id));
75 } 75 }
76 76
77 // static
78 void Window::CloseSecondaryWidget(Widget* widget) {
79 if (!widget)
80 return;
81
82 // Close widget if it's identified as a secondary window.
83 Window* window = widget->GetWindow();
84 if (window) {
85 if (!window->IsAppWindow())
86 window->CloseWindow();
87 } else {
88 // If it's not a Window, then close it anyway since it probably is
89 // secondary.
90 widget->Close();
91 }
92 }
93
94 void Window::InitWindow(const InitParams& params) { 77 void Window::InitWindow(const InitParams& params) {
95 window_delegate_ = params.window_delegate; 78 window_delegate_ = params.window_delegate;
96 AsWidget()->set_widget_delegate(window_delegate_); 79 AsWidget()->set_widget_delegate(window_delegate_);
97 DCHECK(window_delegate_); 80 DCHECK(window_delegate_);
98 DCHECK(!window_delegate_->window_); 81 DCHECK(!window_delegate_->window_);
99 window_delegate_->window_ = this; 82 window_delegate_->window_ = this;
83 set_widget_delegate(window_delegate_);
84 native_window_ =
85 params.native_window ? params.native_window
86 : NativeWindow::CreateNativeWindow(this);
100 // If frame_view was set already, don't replace it with default one. 87 // If frame_view was set already, don't replace it with default one.
101 if (!non_client_view()->frame_view()) 88 if (!non_client_view()->frame_view())
102 non_client_view()->SetFrameView(CreateFrameViewForWindow()); 89 non_client_view()->SetFrameView(CreateFrameViewForWindow());
103 AsWidget()->Init(params.widget_init_params); 90 InitParams modified_params = params;
104 OnNativeWindowCreated(params.widget_init_params.bounds); 91 modified_params.widget_init_params.native_widget =
92 native_window_->AsNativeWidget();
93 Init(modified_params.widget_init_params);
94 OnNativeWindowCreated(modified_params.widget_init_params.bounds);
105 } 95 }
106 96
107 gfx::Rect Window::GetBounds() const { 97 gfx::Rect Window::GetBounds() const {
108 // TODO(beng): Clean this up once Window subclasses Widget. 98 // TODO(beng): Clean this up once Window subclasses Widget.
109 return native_window_->AsNativeWidget()->GetWidget()->GetWindowScreenBounds(); 99 return native_window_->AsNativeWidget()->GetWidget()->GetWindowScreenBounds();
110 } 100 }
111 101
112 gfx::Rect Window::GetNormalBounds() const { 102 gfx::Rect Window::GetNormalBounds() const {
113 return native_window_->GetRestoredBounds(); 103 return native_window_->GetRestoredBounds();
114 } 104 }
(...skipping 27 matching lines...) Expand all
142 } 132 }
143 133
144 void Window::Activate() { 134 void Window::Activate() {
145 native_window_->Activate(); 135 native_window_->Activate();
146 } 136 }
147 137
148 void Window::Deactivate() { 138 void Window::Deactivate() {
149 native_window_->Deactivate(); 139 native_window_->Deactivate();
150 } 140 }
151 141
152 void Window::CloseWindow() { 142 void Window::Close() {
153 if (window_closed_) { 143 if (window_closed_) {
154 // It appears we can hit this code path if you close a modal dialog then 144 // It appears we can hit this code path if you close a modal dialog then
155 // close the last browser before the destructor is hit, which triggers 145 // close the last browser before the destructor is hit, which triggers
156 // invoking Close again. 146 // invoking Close again.
157 return; 147 return;
158 } 148 }
159 149
160 if (non_client_view_->CanClose()) { 150 if (non_client_view_->CanClose()) {
161 SaveWindowPosition(); 151 SaveWindowPosition();
162 // TODO(beng): This can be simplified to Widget::Close() once Window 152 Widget::Close();
163 // subclasses Widget.
164 native_window_->AsNativeWidget()->GetWidget()->Close();
165 window_closed_ = true; 153 window_closed_ = true;
166 } 154 }
167 } 155 }
168 156
169 void Window::Maximize() { 157 void Window::Maximize() {
170 native_window_->Maximize(); 158 native_window_->Maximize();
171 } 159 }
172 160
173 void Window::Minimize() { 161 void Window::Minimize() {
174 native_window_->Minimize(); 162 native_window_->Minimize();
(...skipping 24 matching lines...) Expand all
199 } 187 }
200 188
201 bool Window::IsFullscreen() const { 189 bool Window::IsFullscreen() const {
202 return native_window_->IsFullscreen(); 190 return native_window_->IsFullscreen();
203 } 191 }
204 192
205 void Window::SetUseDragFrame(bool use_drag_frame) { 193 void Window::SetUseDragFrame(bool use_drag_frame) {
206 native_window_->SetUseDragFrame(use_drag_frame); 194 native_window_->SetUseDragFrame(use_drag_frame);
207 } 195 }
208 196
209 bool Window::IsAppWindow() const {
210 return native_window_->IsAppWindow();
211 }
212
213 void Window::EnableClose(bool enable) { 197 void Window::EnableClose(bool enable) {
214 non_client_view_->EnableClose(enable); 198 non_client_view_->EnableClose(enable);
215 native_window_->EnableClose(enable); 199 native_window_->EnableClose(enable);
216 } 200 }
217 201
218 void Window::UpdateWindowTitle() { 202 void Window::UpdateWindowTitle() {
219 // If the non-client view is rendering its own title, it'll need to relayout 203 // If the non-client view is rendering its own title, it'll need to relayout
220 // now. 204 // now.
221 non_client_view_->Layout(); 205 non_client_view_->Layout();
222 206
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 238 }
255 239
256 bool Window::ShouldUseNativeFrame() const { 240 bool Window::ShouldUseNativeFrame() const {
257 return native_window_->ShouldUseNativeFrame(); 241 return native_window_->ShouldUseNativeFrame();
258 } 242 }
259 243
260 void Window::FrameTypeChanged() { 244 void Window::FrameTypeChanged() {
261 native_window_->FrameTypeChanged(); 245 native_window_->FrameTypeChanged();
262 } 246 }
263 247
264 Widget* Window::AsWidget() {
265 return const_cast<Widget*>(const_cast<const Window*>(this)->AsWidget());
266 }
267
268 const Widget* Window::AsWidget() const {
269 return native_window_->AsNativeWidget()->GetWidget();
270 }
271
272 ////////////////////////////////////////////////////////////////////////////////
273 // Window, protected:
274
275 void Window::SetNativeWindow(NativeWindow* native_window) {
276 native_window_ = native_window;
277 }
278
279 //////////////////////////////////////////////////////////////////////////////// 248 ////////////////////////////////////////////////////////////////////////////////
280 // Window, internal::NativeWindowDelegate implementation: 249 // Window, internal::NativeWindowDelegate implementation:
281 250
282 bool Window::CanActivate() const { 251 bool Window::CanActivate() const {
283 return window_delegate_->CanActivate(); 252 return window_delegate_->CanActivate();
284 } 253 }
285 254
286 bool Window::IsInactiveRenderingDisabled() const { 255 bool Window::IsInactiveRenderingDisabled() const {
287 return disable_inactive_rendering_; 256 return disable_inactive_rendering_;
288 } 257 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 326
358 void Window::OnNativeWindowDestroyed() { 327 void Window::OnNativeWindowDestroyed() {
359 window_delegate_->DeleteDelegate(); 328 window_delegate_->DeleteDelegate();
360 window_delegate_ = NULL; 329 window_delegate_ = NULL;
361 } 330 }
362 331
363 void Window::OnNativeWindowBoundsChanged() { 332 void Window::OnNativeWindowBoundsChanged() {
364 SaveWindowPosition(); 333 SaveWindowPosition();
365 } 334 }
366 335
336 Window* Window::AsWindow() {
337 return this;
338 }
339
340 internal::NativeWidgetDelegate* Window::AsNativeWidgetDelegate() {
341 return this;
342 }
343
367 //////////////////////////////////////////////////////////////////////////////// 344 ////////////////////////////////////////////////////////////////////////////////
368 // Window, private: 345 // Window, private:
369 346
370 void Window::SetInitialBounds(const gfx::Rect& bounds) { 347 void Window::SetInitialBounds(const gfx::Rect& bounds) {
371 // First we obtain the window's saved show-style and store it. We need to do 348 // First we obtain the window's saved show-style and store it. We need to do
372 // this here, rather than in Show() because by the time Show() is called, 349 // this here, rather than in Show() because by the time Show() is called,
373 // the window's size will have been reset (below) and the saved maximized 350 // the window's size will have been reset (below) and the saved maximized
374 // state will have been lost. Sadly there's no way to tell on Windows when 351 // state will have been lost. Sadly there's no way to tell on Windows when
375 // a window is restored from maximized state, so we can't more accurately 352 // a window is restored from maximized state, so we can't more accurately
376 // track maximized state independently of sizing information. 353 // track maximized state independently of sizing information.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 if (!window_delegate_) 400 if (!window_delegate_)
424 return; 401 return;
425 402
426 bool maximized; 403 bool maximized;
427 gfx::Rect bounds; 404 gfx::Rect bounds;
428 native_window_->GetWindowBoundsAndMaximizedState(&bounds, &maximized); 405 native_window_->GetWindowBoundsAndMaximizedState(&bounds, &maximized);
429 window_delegate_->SaveWindowPlacement(bounds, maximized); 406 window_delegate_->SaveWindowPlacement(bounds, maximized);
430 } 407 }
431 408
432 } // namespace views 409 } // namespace views
OLDNEW
« no previous file with comments | « views/window/window.h ('k') | views/window/window_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698