OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/views/default_non_client_view.h" | 5 #include "chrome/views/custom_frame_view.h" |
6 | 6 |
7 #include "base/win_util.h" | 7 #include "base/win_util.h" |
8 #include "chrome/common/gfx/path.h" | 8 #include "chrome/common/gfx/path.h" |
9 #include "chrome/common/gfx/chrome_font.h" | 9 #include "chrome/common/gfx/chrome_font.h" |
10 #include "chrome/common/resource_bundle.h" | 10 #include "chrome/common/resource_bundle.h" |
11 #include "chrome/common/win_util.h" | 11 #include "chrome/common/win_util.h" |
12 #include "chrome/views/client_view.h" | 12 #include "chrome/views/client_view.h" |
| 13 #include "chrome/views/window_delegate.h" |
13 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
14 | 15 |
15 namespace views { | 16 namespace views { |
16 | 17 |
17 // An enumeration of bitmap resources used by this window. | 18 // An enumeration of bitmap resources used by this window. |
18 enum { | 19 enum { |
19 FRAME_PART_BITMAP_FIRST = 0, // Must be first. | 20 FRAME_PART_BITMAP_FIRST = 0, // Must be first. |
20 | 21 |
21 // Window Controls. | 22 // Window Controls. |
22 FRAME_CLOSE_BUTTON_ICON, | 23 FRAME_CLOSE_BUTTON_ICON, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 static SkBitmap* standard_frame_bitmaps_[FRAME_PART_BITMAP_COUNT]; | 158 static SkBitmap* standard_frame_bitmaps_[FRAME_PART_BITMAP_COUNT]; |
158 | 159 |
159 DISALLOW_EVIL_CONSTRUCTORS(InactiveWindowResources); | 160 DISALLOW_EVIL_CONSTRUCTORS(InactiveWindowResources); |
160 }; | 161 }; |
161 | 162 |
162 // static | 163 // static |
163 SkBitmap* ActiveWindowResources::standard_frame_bitmaps_[]; | 164 SkBitmap* ActiveWindowResources::standard_frame_bitmaps_[]; |
164 SkBitmap* InactiveWindowResources::standard_frame_bitmaps_[]; | 165 SkBitmap* InactiveWindowResources::standard_frame_bitmaps_[]; |
165 | 166 |
166 // static | 167 // static |
167 WindowResources* DefaultNonClientView::active_resources_ = NULL; | 168 WindowResources* CustomFrameView::active_resources_ = NULL; |
168 WindowResources* DefaultNonClientView::inactive_resources_ = NULL; | 169 WindowResources* CustomFrameView::inactive_resources_ = NULL; |
169 ChromeFont DefaultNonClientView::title_font_; | 170 ChromeFont CustomFrameView::title_font_; |
170 | 171 |
171 namespace { | 172 namespace { |
172 // The frame border is only visible in restored mode and is hardcoded to 4 px on | 173 // The frame border is only visible in restored mode and is hardcoded to 4 px on |
173 // each side regardless of the system window border size. | 174 // each side regardless of the system window border size. |
174 const int kFrameBorderThickness = 4; | 175 const int kFrameBorderThickness = 4; |
175 // Various edges of the frame border have a 1 px shadow along their edges; in a | 176 // Various edges of the frame border have a 1 px shadow along their edges; in a |
176 // few cases we shift elements based on this amount for visual appeal. | 177 // few cases we shift elements based on this amount for visual appeal. |
177 const int kFrameShadowThickness = 1; | 178 const int kFrameShadowThickness = 1; |
178 // While resize areas on Windows are normally the same size as the window | 179 // While resize areas on Windows are normally the same size as the window |
179 // borders, our top area is shrunk by 1 px to make it easier to move the window | 180 // borders, our top area is shrunk by 1 px to make it easier to move the window |
(...skipping 26 matching lines...) Expand all Loading... |
206 const int kTitleTopSpacing = 2; | 207 const int kTitleTopSpacing = 2; |
207 // There is a 5 px gap between the title text and the caption buttons. | 208 // There is a 5 px gap between the title text and the caption buttons. |
208 const int kTitleCaptionSpacing = 5; | 209 const int kTitleCaptionSpacing = 5; |
209 // The caption buttons are always drawn 1 px down from the visible top of the | 210 // The caption buttons are always drawn 1 px down from the visible top of the |
210 // window (the true top in restored mode, or the top of the screen in maximized | 211 // window (the true top in restored mode, or the top of the screen in maximized |
211 // mode). | 212 // mode). |
212 const int kCaptionTopSpacing = 1; | 213 const int kCaptionTopSpacing = 1; |
213 } | 214 } |
214 | 215 |
215 /////////////////////////////////////////////////////////////////////////////// | 216 /////////////////////////////////////////////////////////////////////////////// |
216 // DefaultNonClientView, public: | 217 // CustomFrameView, public: |
217 | 218 |
218 DefaultNonClientView::DefaultNonClientView( | 219 CustomFrameView::CustomFrameView(Window* frame) |
219 CustomFrameWindow* container) | 220 : NonClientFrameView(), |
220 : NonClientView(), | |
221 client_view_(NULL), | |
222 close_button_(new Button), | 221 close_button_(new Button), |
223 restore_button_(new Button), | 222 restore_button_(new Button), |
224 maximize_button_(new Button), | 223 maximize_button_(new Button), |
225 minimize_button_(new Button), | 224 minimize_button_(new Button), |
226 system_menu_button_(new Button), | 225 system_menu_button_(new Button), |
227 should_show_minmax_buttons_(false), | 226 should_show_minmax_buttons_(false), |
228 container_(container) { | 227 frame_(frame) { |
229 InitClass(); | 228 InitClass(); |
230 WindowResources* resources = active_resources_; | 229 WindowResources* resources = active_resources_; |
231 | 230 |
232 // Close button images will be set in LayoutWindowControls(). | 231 // Close button images will be set in LayoutWindowControls(). |
233 close_button_->SetListener(this, -1); | 232 close_button_->SetListener(this, -1); |
234 AddChildView(close_button_); | 233 AddChildView(close_button_); |
235 | 234 |
236 restore_button_->SetImage(Button::BS_NORMAL, | 235 restore_button_->SetImage(Button::BS_NORMAL, |
237 resources->GetPartBitmap(FRAME_RESTORE_BUTTON_ICON)); | 236 resources->GetPartBitmap(FRAME_RESTORE_BUTTON_ICON)); |
238 restore_button_->SetImage(Button::BS_HOT, | 237 restore_button_->SetImage(Button::BS_HOT, |
(...skipping 14 matching lines...) Expand all Loading... |
253 | 252 |
254 minimize_button_->SetImage(Button::BS_NORMAL, | 253 minimize_button_->SetImage(Button::BS_NORMAL, |
255 resources->GetPartBitmap(FRAME_MINIMIZE_BUTTON_ICON)); | 254 resources->GetPartBitmap(FRAME_MINIMIZE_BUTTON_ICON)); |
256 minimize_button_->SetImage(Button::BS_HOT, | 255 minimize_button_->SetImage(Button::BS_HOT, |
257 resources->GetPartBitmap(FRAME_MINIMIZE_BUTTON_ICON_H)); | 256 resources->GetPartBitmap(FRAME_MINIMIZE_BUTTON_ICON_H)); |
258 minimize_button_->SetImage(Button::BS_PUSHED, | 257 minimize_button_->SetImage(Button::BS_PUSHED, |
259 resources->GetPartBitmap(FRAME_MINIMIZE_BUTTON_ICON_P)); | 258 resources->GetPartBitmap(FRAME_MINIMIZE_BUTTON_ICON_P)); |
260 minimize_button_->SetListener(this, -1); | 259 minimize_button_->SetListener(this, -1); |
261 AddChildView(minimize_button_); | 260 AddChildView(minimize_button_); |
262 | 261 |
263 should_show_minmax_buttons_ = container->window_delegate()->CanMaximize(); | 262 should_show_minmax_buttons_ = frame_->window_delegate()->CanMaximize(); |
264 | 263 |
265 AddChildView(system_menu_button_); | 264 AddChildView(system_menu_button_); |
266 } | 265 } |
267 | 266 |
268 DefaultNonClientView::~DefaultNonClientView() { | 267 CustomFrameView::~CustomFrameView() { |
269 } | 268 } |
270 | 269 |
271 /////////////////////////////////////////////////////////////////////////////// | 270 /////////////////////////////////////////////////////////////////////////////// |
272 // DefaultNonClientView, CustomFrameWindow::NonClientView implementation: | 271 // CustomFrameView, NonClientFrameView implementation: |
273 | 272 |
274 gfx::Rect DefaultNonClientView::CalculateClientAreaBounds(int width, | 273 gfx::Rect CustomFrameView::GetBoundsForClientView() const { |
275 int height) const { | 274 return client_view_bounds_; |
| 275 } |
| 276 |
| 277 gfx::Rect CustomFrameView::GetWindowBoundsForClientBounds( |
| 278 const gfx::Rect& client_bounds) const { |
276 int top_height = NonClientTopBorderHeight(); | 279 int top_height = NonClientTopBorderHeight(); |
277 int border_thickness = NonClientBorderThickness(); | 280 int border_thickness = NonClientBorderThickness(); |
278 return gfx::Rect(border_thickness, top_height, | 281 return gfx::Rect(std::max(0, client_bounds.x() - border_thickness), |
279 std::max(0, width - (2 * border_thickness)), | 282 std::max(0, client_bounds.y() - top_height), |
280 std::max(0, height - top_height - border_thickness)); | 283 client_bounds.width() + (2 * border_thickness), |
| 284 client_bounds.height() + top_height + border_thickness); |
281 } | 285 } |
282 | 286 |
283 gfx::Size DefaultNonClientView::CalculateWindowSizeForClientSize( | 287 gfx::Point CustomFrameView::GetSystemMenuPoint() const { |
284 int width, | |
285 int height) const { | |
286 int border_thickness = NonClientBorderThickness(); | |
287 return gfx::Size(width + (2 * border_thickness), | |
288 height + NonClientTopBorderHeight() + border_thickness); | |
289 } | |
290 | |
291 gfx::Point DefaultNonClientView::GetSystemMenuPoint() const { | |
292 gfx::Point system_menu_point(FrameBorderThickness(), | 288 gfx::Point system_menu_point(FrameBorderThickness(), |
293 NonClientTopBorderHeight() - BottomEdgeThicknessWithinNonClientHeight()); | 289 NonClientTopBorderHeight() - BottomEdgeThicknessWithinNonClientHeight()); |
294 ConvertPointToScreen(this, &system_menu_point); | 290 ConvertPointToScreen(this, &system_menu_point); |
295 return system_menu_point; | 291 return system_menu_point; |
296 } | 292 } |
297 | 293 |
298 int DefaultNonClientView::NonClientHitTest(const gfx::Point& point) { | 294 int CustomFrameView::NonClientHitTest(const gfx::Point& point) { |
299 if (!bounds().Contains(point)) | |
300 return HTNOWHERE; | |
301 | |
302 int frame_component = container_->client_view()->NonClientHitTest(point); | |
303 if (frame_component != HTNOWHERE) | |
304 return frame_component; | |
305 | |
306 // Then see if the point is within any of the window controls. | 295 // Then see if the point is within any of the window controls. |
307 if (close_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains(point)) | 296 if (close_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains(point)) |
308 return HTCLOSE; | 297 return HTCLOSE; |
309 if (restore_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains( | 298 if (restore_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains( |
310 point)) | 299 point)) |
311 return HTMAXBUTTON; | 300 return HTMAXBUTTON; |
312 if (maximize_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains( | 301 if (maximize_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains( |
313 point)) | 302 point)) |
314 return HTMAXBUTTON; | 303 return HTMAXBUTTON; |
315 if (minimize_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains( | 304 if (minimize_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains( |
316 point)) | 305 point)) |
317 return HTMINBUTTON; | 306 return HTMINBUTTON; |
318 if (system_menu_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains( | 307 if (system_menu_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains( |
319 point)) | 308 point)) |
320 return HTSYSMENU; | 309 return HTSYSMENU; |
321 | 310 |
322 int window_component = GetHTComponentForFrame(point, FrameBorderThickness(), | 311 int window_component = GetHTComponentForFrame(point, FrameBorderThickness(), |
323 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, | 312 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, |
324 container_->window_delegate()->CanResize()); | 313 frame_->window_delegate()->CanResize()); |
325 // Fall back to the caption if no other component matches. | 314 // Fall back to the caption if no other component matches. |
326 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; | 315 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; |
327 } | 316 } |
328 | 317 |
329 void DefaultNonClientView::GetWindowMask(const gfx::Size& size, | 318 void CustomFrameView::GetWindowMask(const gfx::Size& size, |
330 gfx::Path* window_mask) { | 319 gfx::Path* window_mask) { |
331 DCHECK(window_mask); | 320 DCHECK(window_mask); |
332 | 321 |
333 // Redefine the window visible region for the new size. | 322 // Redefine the window visible region for the new size. |
334 window_mask->moveTo(0, 3); | 323 window_mask->moveTo(0, 3); |
335 window_mask->lineTo(1, 2); | 324 window_mask->lineTo(1, 2); |
336 window_mask->lineTo(1, 1); | 325 window_mask->lineTo(1, 1); |
337 window_mask->lineTo(2, 1); | 326 window_mask->lineTo(2, 1); |
338 window_mask->lineTo(3, 0); | 327 window_mask->lineTo(3, 0); |
339 | 328 |
340 window_mask->lineTo(SkIntToScalar(size.width() - 3), 0); | 329 window_mask->lineTo(SkIntToScalar(size.width() - 3), 0); |
341 window_mask->lineTo(SkIntToScalar(size.width() - 2), 1); | 330 window_mask->lineTo(SkIntToScalar(size.width() - 2), 1); |
342 window_mask->lineTo(SkIntToScalar(size.width() - 1), 1); | 331 window_mask->lineTo(SkIntToScalar(size.width() - 1), 1); |
343 window_mask->lineTo(SkIntToScalar(size.width() - 1), 2); | 332 window_mask->lineTo(SkIntToScalar(size.width() - 1), 2); |
344 window_mask->lineTo(SkIntToScalar(size.width()), 3); | 333 window_mask->lineTo(SkIntToScalar(size.width()), 3); |
345 | 334 |
346 window_mask->lineTo(SkIntToScalar(size.width()), | 335 window_mask->lineTo(SkIntToScalar(size.width()), |
347 SkIntToScalar(size.height())); | 336 SkIntToScalar(size.height())); |
348 window_mask->lineTo(0, SkIntToScalar(size.height())); | 337 window_mask->lineTo(0, SkIntToScalar(size.height())); |
349 window_mask->close(); | 338 window_mask->close(); |
350 } | 339 } |
351 | 340 |
352 void DefaultNonClientView::EnableClose(bool enable) { | 341 void CustomFrameView::EnableClose(bool enable) { |
353 close_button_->SetEnabled(enable); | 342 close_button_->SetEnabled(enable); |
354 } | 343 } |
355 | 344 |
356 void DefaultNonClientView::ResetWindowControls() { | 345 void CustomFrameView::ResetWindowControls() { |
357 restore_button_->SetState(Button::BS_NORMAL); | 346 restore_button_->SetState(Button::BS_NORMAL); |
358 minimize_button_->SetState(Button::BS_NORMAL); | 347 minimize_button_->SetState(Button::BS_NORMAL); |
359 maximize_button_->SetState(Button::BS_NORMAL); | 348 maximize_button_->SetState(Button::BS_NORMAL); |
360 // The close button isn't affected by this constraint. | 349 // The close button isn't affected by this constraint. |
361 } | 350 } |
362 | 351 |
363 /////////////////////////////////////////////////////////////////////////////// | 352 /////////////////////////////////////////////////////////////////////////////// |
364 // DefaultNonClientView, View overrides: | 353 // CustomFrameView, View overrides: |
365 | 354 |
366 void DefaultNonClientView::Paint(ChromeCanvas* canvas) { | 355 void CustomFrameView::Paint(ChromeCanvas* canvas) { |
367 if (container_->IsMaximized()) | 356 if (frame_->IsMaximized()) |
368 PaintMaximizedFrameBorder(canvas); | 357 PaintMaximizedFrameBorder(canvas); |
369 else | 358 else |
370 PaintRestoredFrameBorder(canvas); | 359 PaintRestoredFrameBorder(canvas); |
371 PaintTitleBar(canvas); | 360 PaintTitleBar(canvas); |
372 if (!container_->IsMaximized()) | 361 if (!frame_->IsMaximized()) |
373 PaintRestoredClientEdge(canvas); | 362 PaintRestoredClientEdge(canvas); |
374 } | 363 } |
375 | 364 |
376 void DefaultNonClientView::Layout() { | 365 void CustomFrameView::Layout() { |
377 LayoutWindowControls(); | 366 LayoutWindowControls(); |
378 LayoutTitleBar(); | 367 LayoutTitleBar(); |
379 LayoutClientView(); | 368 LayoutClientView(); |
380 } | 369 } |
381 | 370 |
382 gfx::Size DefaultNonClientView::GetPreferredSize() { | 371 gfx::Size CustomFrameView::GetPreferredSize() { |
383 gfx::Size pref = client_view_->GetPreferredSize(); | 372 gfx::Size pref = frame_->client_view()->GetPreferredSize(); |
384 DCHECK(pref.width() > 0 && pref.height() > 0); | 373 DCHECK(pref.width() > 0 && pref.height() > 0); |
385 return CalculateWindowSizeForClientSize(pref.width(), pref.height()); | 374 gfx::Rect bounds(0, 0, pref.width(), pref.height()); |
386 } | 375 return frame_->GetWindowBoundsForClientBounds(bounds).size(); |
387 | |
388 void DefaultNonClientView::ViewHierarchyChanged(bool is_add, | |
389 View* parent, | |
390 View* child) { | |
391 // Add our Client View as we are added to the Widget so that if we are | |
392 // subsequently resized all the parent-child relationships are established. | |
393 if (is_add && GetWidget() && child == this) | |
394 AddChildView(container_->client_view()); | |
395 } | 376 } |
396 | 377 |
397 /////////////////////////////////////////////////////////////////////////////// | 378 /////////////////////////////////////////////////////////////////////////////// |
398 // DefaultNonClientView, BaseButton::ButtonListener implementation: | 379 // CustomFrameView, BaseButton::ButtonListener implementation: |
399 | 380 |
400 void DefaultNonClientView::ButtonPressed(BaseButton* sender) { | 381 void CustomFrameView::ButtonPressed(BaseButton* sender) { |
401 if (sender == close_button_) | 382 if (sender == close_button_) |
402 container_->ExecuteSystemMenuCommand(SC_CLOSE); | 383 frame_->ExecuteSystemMenuCommand(SC_CLOSE); |
403 else if (sender == minimize_button_) | 384 else if (sender == minimize_button_) |
404 container_->ExecuteSystemMenuCommand(SC_MINIMIZE); | 385 frame_->ExecuteSystemMenuCommand(SC_MINIMIZE); |
405 else if (sender == maximize_button_) | 386 else if (sender == maximize_button_) |
406 container_->ExecuteSystemMenuCommand(SC_MAXIMIZE); | 387 frame_->ExecuteSystemMenuCommand(SC_MAXIMIZE); |
407 else if (sender == restore_button_) | 388 else if (sender == restore_button_) |
408 container_->ExecuteSystemMenuCommand(SC_RESTORE); | 389 frame_->ExecuteSystemMenuCommand(SC_RESTORE); |
409 } | 390 } |
410 | 391 |
411 /////////////////////////////////////////////////////////////////////////////// | 392 /////////////////////////////////////////////////////////////////////////////// |
412 // DefaultNonClientView, private: | 393 // CustomFrameView, private: |
413 | 394 |
414 int DefaultNonClientView::FrameBorderThickness() const { | 395 int CustomFrameView::FrameBorderThickness() const { |
415 return container_->IsMaximized() ? | 396 return frame_->IsMaximized() ? |
416 GetSystemMetrics(SM_CXSIZEFRAME) : kFrameBorderThickness; | 397 GetSystemMetrics(SM_CXSIZEFRAME) : kFrameBorderThickness; |
417 } | 398 } |
418 | 399 |
419 int DefaultNonClientView::NonClientBorderThickness() const { | 400 int CustomFrameView::NonClientBorderThickness() const { |
420 // In maximized mode, we don't show a client edge. | 401 // In maximized mode, we don't show a client edge. |
421 return FrameBorderThickness() + | 402 return FrameBorderThickness() + |
422 (container_->IsMaximized() ? 0 : kClientEdgeThickness); | 403 (frame_->IsMaximized() ? 0 : kClientEdgeThickness); |
423 } | 404 } |
424 | 405 |
425 int DefaultNonClientView::NonClientTopBorderHeight() const { | 406 int CustomFrameView::NonClientTopBorderHeight() const { |
426 int title_top_spacing, title_thickness; | 407 int title_top_spacing, title_thickness; |
427 return TitleCoordinates(&title_top_spacing, &title_thickness); | 408 return TitleCoordinates(&title_top_spacing, &title_thickness); |
428 } | 409 } |
429 | 410 |
430 int DefaultNonClientView::BottomEdgeThicknessWithinNonClientHeight() const { | 411 int CustomFrameView::BottomEdgeThicknessWithinNonClientHeight() const { |
431 return kFrameShadowThickness + | 412 return kFrameShadowThickness + |
432 (container_->IsMaximized() ? 0 : kClientEdgeThickness); | 413 (frame_->IsMaximized() ? 0 : kClientEdgeThickness); |
433 } | 414 } |
434 | 415 |
435 int DefaultNonClientView::TitleCoordinates(int* title_top_spacing, | 416 int CustomFrameView::TitleCoordinates(int* title_top_spacing, |
436 int* title_thickness) const { | 417 int* title_thickness) const { |
437 int frame_thickness = FrameBorderThickness(); | 418 int frame_thickness = FrameBorderThickness(); |
438 int min_titlebar_height = kTitlebarMinimumHeight + frame_thickness; | 419 int min_titlebar_height = kTitlebarMinimumHeight + frame_thickness; |
439 *title_top_spacing = frame_thickness + kTitleTopSpacing; | 420 *title_top_spacing = frame_thickness + kTitleTopSpacing; |
440 // The bottom spacing should be the same apparent height as the top spacing. | 421 // The bottom spacing should be the same apparent height as the top spacing. |
441 // Because the actual top spacing height varies based on the system border | 422 // Because the actual top spacing height varies based on the system border |
442 // thickness, we calculate this based on the restored top spacing and then | 423 // thickness, we calculate this based on the restored top spacing and then |
443 // adjust for maximized mode. We also don't include the frame shadow here, | 424 // adjust for maximized mode. We also don't include the frame shadow here, |
444 // since while it's part of the bottom spacing it will be added in at the end. | 425 // since while it's part of the bottom spacing it will be added in at the end. |
445 int title_bottom_spacing = | 426 int title_bottom_spacing = |
446 kFrameBorderThickness + kTitleTopSpacing - kFrameShadowThickness; | 427 kFrameBorderThickness + kTitleTopSpacing - kFrameShadowThickness; |
447 if (container_->IsMaximized()) { | 428 if (frame_->IsMaximized()) { |
448 // When we maximize, the top border appears to be chopped off; shift the | 429 // When we maximize, the top border appears to be chopped off; shift the |
449 // title down to stay centered within the remaining space. | 430 // title down to stay centered within the remaining space. |
450 int title_adjust = (kFrameBorderThickness / 2); | 431 int title_adjust = (kFrameBorderThickness / 2); |
451 *title_top_spacing += title_adjust; | 432 *title_top_spacing += title_adjust; |
452 title_bottom_spacing -= title_adjust; | 433 title_bottom_spacing -= title_adjust; |
453 } | 434 } |
454 *title_thickness = std::max(title_font_.height(), | 435 *title_thickness = std::max(title_font_.height(), |
455 min_titlebar_height - *title_top_spacing - title_bottom_spacing); | 436 min_titlebar_height - *title_top_spacing - title_bottom_spacing); |
456 return *title_top_spacing + *title_thickness + title_bottom_spacing + | 437 return *title_top_spacing + *title_thickness + title_bottom_spacing + |
457 BottomEdgeThicknessWithinNonClientHeight(); | 438 BottomEdgeThicknessWithinNonClientHeight(); |
458 } | 439 } |
459 | 440 |
460 void DefaultNonClientView::PaintRestoredFrameBorder(ChromeCanvas* canvas) { | 441 void CustomFrameView::PaintRestoredFrameBorder(ChromeCanvas* canvas) { |
461 SkBitmap* top_left_corner = resources()->GetPartBitmap(FRAME_TOP_LEFT_CORNER); | 442 SkBitmap* top_left_corner = resources()->GetPartBitmap(FRAME_TOP_LEFT_CORNER); |
462 SkBitmap* top_right_corner = | 443 SkBitmap* top_right_corner = |
463 resources()->GetPartBitmap(FRAME_TOP_RIGHT_CORNER); | 444 resources()->GetPartBitmap(FRAME_TOP_RIGHT_CORNER); |
464 SkBitmap* top_edge = resources()->GetPartBitmap(FRAME_TOP_EDGE); | 445 SkBitmap* top_edge = resources()->GetPartBitmap(FRAME_TOP_EDGE); |
465 SkBitmap* right_edge = resources()->GetPartBitmap(FRAME_RIGHT_EDGE); | 446 SkBitmap* right_edge = resources()->GetPartBitmap(FRAME_RIGHT_EDGE); |
466 SkBitmap* left_edge = resources()->GetPartBitmap(FRAME_LEFT_EDGE); | 447 SkBitmap* left_edge = resources()->GetPartBitmap(FRAME_LEFT_EDGE); |
467 SkBitmap* bottom_left_corner = | 448 SkBitmap* bottom_left_corner = |
468 resources()->GetPartBitmap(FRAME_BOTTOM_LEFT_CORNER); | 449 resources()->GetPartBitmap(FRAME_BOTTOM_LEFT_CORNER); |
469 SkBitmap* bottom_right_corner = | 450 SkBitmap* bottom_right_corner = |
470 resources()->GetPartBitmap(FRAME_BOTTOM_RIGHT_CORNER); | 451 resources()->GetPartBitmap(FRAME_BOTTOM_RIGHT_CORNER); |
(...skipping 23 matching lines...) Expand all Loading... |
494 bottom_edge->height()); | 475 bottom_edge->height()); |
495 canvas->DrawBitmapInt(*bottom_left_corner, 0, | 476 canvas->DrawBitmapInt(*bottom_left_corner, 0, |
496 height() - bottom_left_corner->height()); | 477 height() - bottom_left_corner->height()); |
497 | 478 |
498 // Left. | 479 // Left. |
499 canvas->TileImageInt(*left_edge, 0, top_left_corner->height(), | 480 canvas->TileImageInt(*left_edge, 0, top_left_corner->height(), |
500 left_edge->width(), | 481 left_edge->width(), |
501 height() - top_left_corner->height() - bottom_left_corner->height()); | 482 height() - top_left_corner->height() - bottom_left_corner->height()); |
502 } | 483 } |
503 | 484 |
504 void DefaultNonClientView::PaintMaximizedFrameBorder( | 485 void CustomFrameView::PaintMaximizedFrameBorder( |
505 ChromeCanvas* canvas) { | 486 ChromeCanvas* canvas) { |
506 SkBitmap* top_edge = resources()->GetPartBitmap(FRAME_TOP_EDGE); | 487 SkBitmap* top_edge = resources()->GetPartBitmap(FRAME_TOP_EDGE); |
507 canvas->TileImageInt(*top_edge, 0, FrameBorderThickness(), width(), | 488 canvas->TileImageInt(*top_edge, 0, FrameBorderThickness(), width(), |
508 top_edge->height()); | 489 top_edge->height()); |
509 | 490 |
510 // The bottom of the titlebar actually comes from the top of the Client Edge | 491 // The bottom of the titlebar actually comes from the top of the Client Edge |
511 // graphic, with the actual client edge clipped off the bottom. | 492 // graphic, with the actual client edge clipped off the bottom. |
512 SkBitmap* titlebar_bottom = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_TOP); | 493 SkBitmap* titlebar_bottom = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_TOP); |
513 int edge_height = titlebar_bottom->height() - kClientEdgeThickness; | 494 int edge_height = titlebar_bottom->height() - kClientEdgeThickness; |
514 canvas->TileImageInt(*titlebar_bottom, 0, | 495 canvas->TileImageInt(*titlebar_bottom, 0, |
515 container_->client_view()->y() - edge_height, width(), edge_height); | 496 frame_->client_view()->y() - edge_height, width(), edge_height); |
516 } | 497 } |
517 | 498 |
518 void DefaultNonClientView::PaintTitleBar(ChromeCanvas* canvas) { | 499 void CustomFrameView::PaintTitleBar(ChromeCanvas* canvas) { |
519 WindowDelegate* d = container_->window_delegate(); | 500 WindowDelegate* d = frame_->window_delegate(); |
520 | 501 |
521 // It seems like in some conditions we can be asked to paint after the window | 502 // It seems like in some conditions we can be asked to paint after the window |
522 // that contains us is WM_DESTROYed. At this point, our delegate is NULL. The | 503 // that contains us is WM_DESTROYed. At this point, our delegate is NULL. The |
523 // correct long term fix may be to shut down the RootView in WM_DESTROY. | 504 // correct long term fix may be to shut down the RootView in WM_DESTROY. |
524 if (!d) | 505 if (!d) |
525 return; | 506 return; |
526 | 507 |
527 canvas->DrawStringInt(d->GetWindowTitle(), title_font_, SK_ColorWHITE, | 508 canvas->DrawStringInt(d->GetWindowTitle(), title_font_, SK_ColorWHITE, |
528 MirroredLeftPointForRect(title_bounds_), title_bounds_.y(), | 509 MirroredLeftPointForRect(title_bounds_), title_bounds_.y(), |
529 title_bounds_.width(), title_bounds_.height()); | 510 title_bounds_.width(), title_bounds_.height()); |
530 } | 511 } |
531 | 512 |
532 void DefaultNonClientView::PaintRestoredClientEdge(ChromeCanvas* canvas) { | 513 void CustomFrameView::PaintRestoredClientEdge(ChromeCanvas* canvas) { |
533 gfx::Rect client_area_bounds = container_->client_view()->bounds(); | 514 gfx::Rect client_area_bounds = frame_->client_view()->bounds(); |
534 int client_area_top = client_area_bounds.y(); | 515 int client_area_top = client_area_bounds.y(); |
535 | 516 |
536 SkBitmap* top_left = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_TOP_LEFT); | 517 SkBitmap* top_left = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_TOP_LEFT); |
537 SkBitmap* top = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_TOP); | 518 SkBitmap* top = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_TOP); |
538 SkBitmap* top_right = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_TOP_RIGHT); | 519 SkBitmap* top_right = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_TOP_RIGHT); |
539 SkBitmap* right = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_RIGHT); | 520 SkBitmap* right = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_RIGHT); |
540 SkBitmap* bottom_right = | 521 SkBitmap* bottom_right = |
541 resources()->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM_RIGHT); | 522 resources()->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM_RIGHT); |
542 SkBitmap* bottom = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM); | 523 SkBitmap* bottom = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM); |
543 SkBitmap* bottom_left = | 524 SkBitmap* bottom_left = |
(...skipping 25 matching lines...) Expand all Loading... |
569 canvas->TileImageInt(*bottom, client_area_bounds.x(), client_area_bottom, | 550 canvas->TileImageInt(*bottom, client_area_bounds.x(), client_area_bottom, |
570 client_area_bounds.width(), bottom_right->height()); | 551 client_area_bounds.width(), bottom_right->height()); |
571 canvas->DrawBitmapInt(*bottom_left, | 552 canvas->DrawBitmapInt(*bottom_left, |
572 client_area_bounds.x() - bottom_left->width(), client_area_bottom); | 553 client_area_bounds.x() - bottom_left->width(), client_area_bottom); |
573 | 554 |
574 // Left. | 555 // Left. |
575 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(), | 556 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(), |
576 client_area_top, left->width(), client_area_height); | 557 client_area_top, left->width(), client_area_height); |
577 } | 558 } |
578 | 559 |
579 void DefaultNonClientView::LayoutWindowControls() { | 560 void CustomFrameView::LayoutWindowControls() { |
580 close_button_->SetImageAlignment(Button::ALIGN_LEFT, Button::ALIGN_BOTTOM); | 561 close_button_->SetImageAlignment(Button::ALIGN_LEFT, Button::ALIGN_BOTTOM); |
581 // Maximized buttons start at window top so that even if their images aren't | 562 // Maximized buttons start at window top so that even if their images aren't |
582 // drawn flush with the screen edge, they still obey Fitts' Law. | 563 // drawn flush with the screen edge, they still obey Fitts' Law. |
583 bool is_maximized = container_->IsMaximized(); | 564 bool is_maximized = frame_->IsMaximized(); |
584 int frame_thickness = FrameBorderThickness(); | 565 int frame_thickness = FrameBorderThickness(); |
585 int caption_y = is_maximized ? frame_thickness : kCaptionTopSpacing; | 566 int caption_y = is_maximized ? frame_thickness : kCaptionTopSpacing; |
586 int top_extra_height = is_maximized ? kCaptionTopSpacing : 0; | 567 int top_extra_height = is_maximized ? kCaptionTopSpacing : 0; |
587 // There should always be the same number of non-shadow pixels visible to the | 568 // There should always be the same number of non-shadow pixels visible to the |
588 // side of the caption buttons. In maximized mode we extend the rightmost | 569 // side of the caption buttons. In maximized mode we extend the rightmost |
589 // button to the screen corner to obey Fitts' Law. | 570 // button to the screen corner to obey Fitts' Law. |
590 int right_extra_width = is_maximized ? | 571 int right_extra_width = is_maximized ? |
591 (kFrameBorderThickness - kFrameShadowThickness) : 0; | 572 (kFrameBorderThickness - kFrameShadowThickness) : 0; |
592 int right_spacing = is_maximized ? | 573 int right_spacing = is_maximized ? |
593 (GetSystemMetrics(SM_CXSIZEFRAME) + right_extra_width) : frame_thickness; | 574 (GetSystemMetrics(SM_CXSIZEFRAME) + right_extra_width) : frame_thickness; |
594 gfx::Size close_button_size = close_button_->GetPreferredSize(); | 575 gfx::Size close_button_size = close_button_->GetPreferredSize(); |
595 close_button_->SetBounds(width() - close_button_size.width() - right_spacing, | 576 close_button_->SetBounds(width() - close_button_size.width() - right_spacing, |
596 caption_y, | 577 caption_y, |
597 close_button_size.width() + right_extra_width, | 578 close_button_size.width() + right_extra_width, |
598 close_button_size.height() + top_extra_height); | 579 close_button_size.height() + top_extra_height); |
599 | 580 |
600 // When the window is restored, we show a maximized button; otherwise, we show | 581 // When the window is restored, we show a maximized button; otherwise, we show |
601 // a restore button. | 582 // a restore button. |
602 bool is_restored = !is_maximized && !container_->IsMinimized(); | 583 bool is_restored = !is_maximized && !frame_->IsMinimized(); |
603 views::Button* invisible_button = is_restored ? | 584 views::Button* invisible_button = is_restored ? |
604 restore_button_ : maximize_button_; | 585 restore_button_ : maximize_button_; |
605 invisible_button->SetVisible(false); | 586 invisible_button->SetVisible(false); |
606 | 587 |
607 views::Button* visible_button = is_restored ? | 588 views::Button* visible_button = is_restored ? |
608 maximize_button_ : restore_button_; | 589 maximize_button_ : restore_button_; |
609 FramePartBitmap normal_part, hot_part, pushed_part; | 590 FramePartBitmap normal_part, hot_part, pushed_part; |
610 if (should_show_minmax_buttons_) { | 591 if (should_show_minmax_buttons_) { |
611 visible_button->SetVisible(true); | 592 visible_button->SetVisible(true); |
612 visible_button->SetImageAlignment(Button::ALIGN_LEFT, Button::ALIGN_BOTTOM); | 593 visible_button->SetImageAlignment(Button::ALIGN_LEFT, Button::ALIGN_BOTTOM); |
(...skipping 24 matching lines...) Expand all Loading... |
637 } | 618 } |
638 | 619 |
639 close_button_->SetImage(Button::BS_NORMAL, | 620 close_button_->SetImage(Button::BS_NORMAL, |
640 active_resources_->GetPartBitmap(normal_part)); | 621 active_resources_->GetPartBitmap(normal_part)); |
641 close_button_->SetImage(Button::BS_HOT, | 622 close_button_->SetImage(Button::BS_HOT, |
642 active_resources_->GetPartBitmap(hot_part)); | 623 active_resources_->GetPartBitmap(hot_part)); |
643 close_button_->SetImage(Button::BS_PUSHED, | 624 close_button_->SetImage(Button::BS_PUSHED, |
644 active_resources_->GetPartBitmap(pushed_part)); | 625 active_resources_->GetPartBitmap(pushed_part)); |
645 } | 626 } |
646 | 627 |
647 void DefaultNonClientView::LayoutTitleBar() { | 628 void CustomFrameView::LayoutTitleBar() { |
648 // Always lay out the icon, even when it's not present, so we can lay out the | 629 // Always lay out the icon, even when it's not present, so we can lay out the |
649 // window title based on its position. | 630 // window title based on its position. |
650 int frame_thickness = FrameBorderThickness(); | 631 int frame_thickness = FrameBorderThickness(); |
651 int icon_x = frame_thickness + kIconLeftSpacing; | 632 int icon_x = frame_thickness + kIconLeftSpacing; |
652 | 633 |
653 // The usable height of the titlebar area is the total height minus the top | 634 // The usable height of the titlebar area is the total height minus the top |
654 // resize border and any edge area we draw at its bottom. | 635 // resize border and any edge area we draw at its bottom. |
655 int title_top_spacing, title_thickness; | 636 int title_top_spacing, title_thickness; |
656 int top_height = TitleCoordinates(&title_top_spacing, &title_thickness); | 637 int top_height = TitleCoordinates(&title_top_spacing, &title_thickness); |
657 int available_height = top_height - frame_thickness - | 638 int available_height = top_height - frame_thickness - |
658 BottomEdgeThicknessWithinNonClientHeight(); | 639 BottomEdgeThicknessWithinNonClientHeight(); |
659 | 640 |
660 // The icon takes up a constant fraction of the available height, down to a | 641 // The icon takes up a constant fraction of the available height, down to a |
661 // minimum size, and is always an even number of pixels on a side (presumably | 642 // minimum size, and is always an even number of pixels on a side (presumably |
662 // to make scaled icons look better). It's centered within the usable height. | 643 // to make scaled icons look better). It's centered within the usable height. |
663 int icon_size = std::max((available_height * kIconHeightFractionNumerator / | 644 int icon_size = std::max((available_height * kIconHeightFractionNumerator / |
664 kIconHeightFractionDenominator) / 2 * 2, kIconMinimumSize); | 645 kIconHeightFractionDenominator) / 2 * 2, kIconMinimumSize); |
665 int icon_y = ((available_height - icon_size) / 2) + frame_thickness; | 646 int icon_y = ((available_height - icon_size) / 2) + frame_thickness; |
666 | 647 |
667 // Hack: Our frame border has a different "3D look" than Windows'. Theirs has | 648 // Hack: Our frame border has a different "3D look" than Windows'. Theirs has |
668 // a more complex gradient on the top that they push their icon/title below; | 649 // a more complex gradient on the top that they push their icon/title below; |
669 // then the maximized window cuts this off and the icon/title are centered in | 650 // then the maximized window cuts this off and the icon/title are centered in |
670 // the remaining space. Because the apparent shape of our border is simpler, | 651 // the remaining space. Because the apparent shape of our border is simpler, |
671 // using the same positioning makes things look slightly uncentered with | 652 // using the same positioning makes things look slightly uncentered with |
672 // restored windows, so we come up to compensate. | 653 // restored windows, so we come up to compensate. |
673 if (!container_->IsMaximized()) | 654 if (!frame_->IsMaximized()) |
674 icon_y -= kIconRestoredAdjust; | 655 icon_y -= kIconRestoredAdjust; |
675 | 656 |
676 views::WindowDelegate* d = container_->window_delegate(); | 657 views::WindowDelegate* d = frame_->window_delegate(); |
677 if (!d->ShouldShowWindowIcon()) | 658 if (!d->ShouldShowWindowIcon()) |
678 icon_size = 0; | 659 icon_size = 0; |
679 system_menu_button_->SetBounds(icon_x, icon_y, icon_size, icon_size); | 660 system_menu_button_->SetBounds(icon_x, icon_y, icon_size, icon_size); |
680 | 661 |
681 // Size the title. | 662 // Size the title. |
682 int icon_right = icon_x + icon_size; | 663 int icon_right = icon_x + icon_size; |
683 int title_x = | 664 int title_x = |
684 icon_right + (d->ShouldShowWindowIcon() ? kIconTitleSpacing : 0); | 665 icon_right + (d->ShouldShowWindowIcon() ? kIconTitleSpacing : 0); |
685 int title_right = (should_show_minmax_buttons_ ? | 666 int title_right = (should_show_minmax_buttons_ ? |
686 minimize_button_->x() : close_button_->x()) - kTitleCaptionSpacing; | 667 minimize_button_->x() : close_button_->x()) - kTitleCaptionSpacing; |
687 title_bounds_.SetRect(title_x, | 668 title_bounds_.SetRect(title_x, |
688 title_top_spacing + ((title_thickness - title_font_.height()) / 2), | 669 title_top_spacing + ((title_thickness - title_font_.height()) / 2), |
689 std::max(0, title_right - title_x), title_font_.height()); | 670 std::max(0, title_right - title_x), title_font_.height()); |
690 } | 671 } |
691 | 672 |
692 void DefaultNonClientView::LayoutClientView() { | 673 void CustomFrameView::LayoutClientView() { |
693 container_->client_view()->SetBounds(CalculateClientAreaBounds(width(), | 674 int top_height = NonClientTopBorderHeight(); |
694 height())); | 675 int border_thickness = NonClientBorderThickness(); |
| 676 client_view_bounds_.SetRect( |
| 677 border_thickness, |
| 678 top_height, |
| 679 std::max(0, width() - (2 * border_thickness)), |
| 680 std::max(0, height() - top_height - border_thickness)); |
695 } | 681 } |
696 | 682 |
697 // static | 683 // static |
698 void DefaultNonClientView::InitClass() { | 684 void CustomFrameView::InitClass() { |
699 static bool initialized = false; | 685 static bool initialized = false; |
700 if (!initialized) { | 686 if (!initialized) { |
701 active_resources_ = new ActiveWindowResources; | 687 active_resources_ = new ActiveWindowResources; |
702 inactive_resources_ = new InactiveWindowResources; | 688 inactive_resources_ = new InactiveWindowResources; |
703 | 689 |
704 title_font_ = win_util::GetWindowTitleFont(); | 690 title_font_ = win_util::GetWindowTitleFont(); |
705 | 691 |
706 initialized = true; | 692 initialized = true; |
707 } | 693 } |
708 } | 694 } |
709 | 695 |
710 } // namespace views | 696 } // namespace views |
| 697 |
OLD | NEW |