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

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

Issue 8772060: Refactor window frame painting into a window background class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: final cleanup of PaintRestored Created 9 years 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 | « ui/views/window/custom_frame_view.h ('k') | ui/views/window/frame_background.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 "ui/views/window/custom_frame_view.h" 5 #include "ui/views/window/custom_frame_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "grit/ui_resources.h" 10 #include "grit/ui_resources.h"
11 #include "grit/ui_strings.h" 11 #include "grit/ui_strings.h"
12 #include "ui/base/hit_test.h" 12 #include "ui/base/hit_test.h"
13 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/gfx/canvas.h" 15 #include "ui/gfx/canvas.h"
16 #include "ui/gfx/font.h" 16 #include "ui/gfx/font.h"
17 #include "ui/gfx/path.h" 17 #include "ui/gfx/path.h"
18 #include "ui/views/widget/widget_delegate.h" 18 #include "ui/views/widget/widget_delegate.h"
19 #include "ui/views/window/client_view.h" 19 #include "ui/views/window/client_view.h"
20 #include "ui/views/window/frame_background.h"
20 #include "ui/views/window/window_resources.h" 21 #include "ui/views/window/window_resources.h"
21 #include "ui/views/window/window_shape.h" 22 #include "ui/views/window/window_shape.h"
22 23
23 #if defined(USE_AURA) 24 #if defined(USE_AURA)
24 #include "ui/views/widget/native_widget_aura.h" 25 #include "ui/views/widget/native_widget_aura.h"
25 #elif defined(OS_WIN) 26 #elif defined(OS_WIN)
26 #include "ui/views/widget/native_widget_win.h" 27 #include "ui/views/widget/native_widget_win.h"
27 #endif 28 #endif
28 29
29 namespace views { 30 namespace views {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // CustomFrameView, public: 67 // CustomFrameView, public:
67 68
68 CustomFrameView::CustomFrameView(Widget* frame) 69 CustomFrameView::CustomFrameView(Widget* frame)
69 : ALLOW_THIS_IN_INITIALIZER_LIST(close_button_(new ImageButton(this))), 70 : ALLOW_THIS_IN_INITIALIZER_LIST(close_button_(new ImageButton(this))),
70 ALLOW_THIS_IN_INITIALIZER_LIST(restore_button_(new ImageButton(this))), 71 ALLOW_THIS_IN_INITIALIZER_LIST(restore_button_(new ImageButton(this))),
71 ALLOW_THIS_IN_INITIALIZER_LIST(maximize_button_(new ImageButton(this))), 72 ALLOW_THIS_IN_INITIALIZER_LIST(maximize_button_(new ImageButton(this))),
72 ALLOW_THIS_IN_INITIALIZER_LIST(minimize_button_(new ImageButton(this))), 73 ALLOW_THIS_IN_INITIALIZER_LIST(minimize_button_(new ImageButton(this))),
73 window_icon_(NULL), 74 window_icon_(NULL),
74 should_show_minmax_buttons_(false), 75 should_show_minmax_buttons_(false),
75 should_show_client_edge_(false), 76 should_show_client_edge_(false),
76 frame_(frame) { 77 frame_(frame),
78 frame_background_(new FrameBackground()) {
77 InitClass(); 79 InitClass();
78 80
79 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 81 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
80 82
81 close_button_->SetAccessibleName( 83 close_button_->SetAccessibleName(
82 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); 84 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE));
83 85
84 // Close button images will be set in LayoutWindowControls(). 86 // Close button images will be set in LayoutWindowControls().
85 AddChildView(close_button_); 87 AddChildView(close_button_);
86 88
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 // 3D edge (or nothing at all, for maximized windows) above; hence the +1. 309 // 3D edge (or nothing at all, for maximized windows) above; hence the +1.
308 int y = unavailable_px_at_top + (NonClientTopBorderHeight() - 310 int y = unavailable_px_at_top + (NonClientTopBorderHeight() -
309 unavailable_px_at_top - size - TitlebarBottomThickness() + 1) / 2; 311 unavailable_px_at_top - size - TitlebarBottomThickness() + 1) / 2;
310 return gfx::Rect(frame_thickness + kIconLeftSpacing, y, size, size); 312 return gfx::Rect(frame_thickness + kIconLeftSpacing, y, size, size);
311 } 313 }
312 314
313 void CustomFrameView::PaintRestoredFrameBorder(gfx::Canvas* canvas) { 315 void CustomFrameView::PaintRestoredFrameBorder(gfx::Canvas* canvas) {
314 // Window frame mode. 316 // Window frame mode.
315 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 317 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
316 318
317 SkBitmap* frame_image; 319 frame_background_->set_frame_color(GetFrameColor());
318 SkColor frame_color; 320 SkBitmap* frame_image = GetFrameBitmap();
319 if (frame_->IsActive()) { 321 frame_background_->set_theme_bitmap(frame_image);
320 frame_image = rb.GetBitmapNamed(IDR_FRAME); 322 frame_background_->set_top_area_height(frame_image->height());
321 frame_color = ResourceBundle::frame_color;
322 } else {
323 frame_image = rb.GetBitmapNamed(IDR_FRAME_INACTIVE);
324 frame_color = ResourceBundle::frame_color_inactive;
325 }
326 323
327 #if defined(USE_AURA) 324 #if defined(USE_AURA)
328 // TODO(jamescook): Remove this when Aura defaults to its own window frame, 325 // TODO(jamescook): Remove this when Aura defaults to its own window frame,
329 // BrowserNonClientFrameViewAura. Until then, use custom square corners to 326 // BrowserNonClientFrameViewAura. Until then, use custom square corners to
330 // avoid performance penalties associated with transparent layers. 327 // avoid performance penalties associated with transparent layers.
331 SkBitmap* top_left_corner = rb.GetBitmapNamed(IDR_AURA_WINDOW_TOP_LEFT); 328 frame_background_->SetCornerImages(
332 SkBitmap* top_right_corner = rb.GetBitmapNamed(IDR_AURA_WINDOW_TOP_RIGHT); 329 rb.GetBitmapNamed(IDR_AURA_WINDOW_TOP_LEFT),
333 SkBitmap* bottom_left_corner = 330 rb.GetBitmapNamed(IDR_AURA_WINDOW_TOP_RIGHT),
334 rb.GetBitmapNamed(IDR_AURA_WINDOW_BOTTOM_LEFT); 331 rb.GetBitmapNamed(IDR_AURA_WINDOW_BOTTOM_LEFT),
335 SkBitmap* bottom_right_corner = 332 rb.GetBitmapNamed(IDR_AURA_WINDOW_BOTTOM_RIGHT));
336 rb.GetBitmapNamed(IDR_AURA_WINDOW_BOTTOM_RIGHT);
337 #else 333 #else
338 SkBitmap* top_left_corner = rb.GetBitmapNamed(IDR_WINDOW_TOP_LEFT_CORNER); 334 frame_background_->SetCornerImages(
339 SkBitmap* top_right_corner = 335 rb.GetBitmapNamed(IDR_WINDOW_TOP_LEFT_CORNER),
340 rb.GetBitmapNamed(IDR_WINDOW_TOP_RIGHT_CORNER); 336 rb.GetBitmapNamed(IDR_WINDOW_TOP_RIGHT_CORNER),
341 SkBitmap* bottom_left_corner = 337 rb.GetBitmapNamed(IDR_WINDOW_BOTTOM_LEFT_CORNER),
342 rb.GetBitmapNamed(IDR_WINDOW_BOTTOM_LEFT_CORNER); 338 rb.GetBitmapNamed(IDR_WINDOW_BOTTOM_RIGHT_CORNER));
343 SkBitmap* bottom_right_corner =
344 rb.GetBitmapNamed(IDR_WINDOW_BOTTOM_RIGHT_CORNER);
345 #endif 339 #endif
346 SkBitmap* top_edge = rb.GetBitmapNamed(IDR_WINDOW_TOP_CENTER); 340 frame_background_->SetSideImages(
347 SkBitmap* right_edge = rb.GetBitmapNamed(IDR_WINDOW_RIGHT_SIDE); 341 rb.GetBitmapNamed(IDR_WINDOW_LEFT_SIDE),
348 SkBitmap* left_edge = rb.GetBitmapNamed(IDR_WINDOW_LEFT_SIDE); 342 rb.GetBitmapNamed(IDR_WINDOW_TOP_CENTER),
349 SkBitmap* bottom_edge = rb.GetBitmapNamed(IDR_WINDOW_BOTTOM_CENTER); 343 rb.GetBitmapNamed(IDR_WINDOW_RIGHT_SIDE),
344 rb.GetBitmapNamed(IDR_WINDOW_BOTTOM_CENTER));
350 345
351 // Fill with the frame color first so we have a constant background for 346 frame_background_->PaintRestored(canvas, this);
352 // areas not covered by the theme image.
353 canvas->FillRect(frame_color,
354 gfx::Rect(0, 0, width(), frame_image->height()));
355
356 int remaining_height = height() - frame_image->height();
357 if (remaining_height > 0) {
358 // Now fill down the sides.
359 canvas->FillRect(frame_color,
360 gfx::Rect(0, frame_image->height(), left_edge->width(),
361 remaining_height));
362 canvas->FillRect(frame_color,
363 gfx::Rect(width() - right_edge->width(),
364 frame_image->height(), right_edge->width(),
365 remaining_height));
366 int center_width = width() - left_edge->width() - right_edge->width();
367 if (center_width > 0) {
368 // Now fill the bottom area.
369 canvas->FillRect(frame_color,
370 gfx::Rect(left_edge->width(),
371 height() - bottom_edge->height(),
372 center_width, bottom_edge->height()));
373 }
374 }
375
376 // Don't draw the colored frame on Aura, just the frame color.
377 #if !defined(USE_AURA)
378 // Draw the theme frame.
379 canvas->TileImageInt(*frame_image, 0, 0, width(), frame_image->height());
380 #endif
381
382 // Top.
383 canvas->DrawBitmapInt(*top_left_corner, 0, 0);
384 canvas->TileImageInt(*top_edge, top_left_corner->width(), 0,
385 width() - top_right_corner->width(), top_edge->height());
386 canvas->DrawBitmapInt(*top_right_corner,
387 width() - top_right_corner->width(), 0);
388
389 // Right.
390 canvas->TileImageInt(*right_edge, width() - right_edge->width(),
391 top_right_corner->height(), right_edge->width(),
392 height() - top_right_corner->height() - bottom_right_corner->height());
393
394 // Bottom.
395 canvas->DrawBitmapInt(*bottom_right_corner,
396 width() - bottom_right_corner->width(),
397 height() - bottom_right_corner->height());
398 canvas->TileImageInt(*bottom_edge, bottom_left_corner->width(),
399 height() - bottom_edge->height(),
400 width() - bottom_left_corner->width() - bottom_right_corner->width(),
401 bottom_edge->height());
402 canvas->DrawBitmapInt(*bottom_left_corner, 0,
403 height() - bottom_left_corner->height());
404
405 // Left.
406 canvas->TileImageInt(*left_edge, 0, top_left_corner->height(),
407 left_edge->width(),
408 height() - top_left_corner->height() - bottom_left_corner->height());
409 } 347 }
410 348
411 void CustomFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) { 349 void CustomFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) {
412 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 350 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
413 351
414 SkBitmap* frame_image = rb.GetBitmapNamed(frame_->IsActive() ? 352 SkBitmap* frame_image = GetFrameBitmap();
415 IDR_FRAME : IDR_FRAME_INACTIVE); 353 frame_background_->set_theme_bitmap(frame_image);
416 canvas->TileImageInt(*frame_image, 0, FrameBorderThickness(), width(), 354 frame_background_->set_top_area_height(frame_image->height());
417 frame_image->height());
418 355
356 frame_background_->PaintMaximized(canvas, this);
357
358 // TODO(jamescook): Migrate this into FrameBackground.
419 // The bottom of the titlebar actually comes from the top of the Client Edge 359 // The bottom of the titlebar actually comes from the top of the Client Edge
420 // graphic, with the actual client edge clipped off the bottom. 360 // graphic, with the actual client edge clipped off the bottom.
421 SkBitmap* titlebar_bottom = rb.GetBitmapNamed(IDR_APP_TOP_CENTER); 361 SkBitmap* titlebar_bottom = rb.GetBitmapNamed(IDR_APP_TOP_CENTER);
422 int edge_height = titlebar_bottom->height() - 362 int edge_height = titlebar_bottom->height() -
423 (ShouldShowClientEdge() ? kClientEdgeThickness : 0); 363 (ShouldShowClientEdge() ? kClientEdgeThickness : 0);
424 canvas->TileImageInt(*titlebar_bottom, 0, 364 canvas->TileImageInt(*titlebar_bottom, 0,
425 frame_->client_view()->y() - edge_height, width(), edge_height); 365 frame_->client_view()->y() - edge_height, width(), edge_height);
426 } 366 }
427 367
428 void CustomFrameView::PaintTitleBar(gfx::Canvas* canvas) { 368 void CustomFrameView::PaintTitleBar(gfx::Canvas* canvas) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 // Left. 422 // Left.
483 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(), 423 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(),
484 client_area_top, left->width(), client_area_height); 424 client_area_top, left->width(), client_area_height);
485 425
486 // Draw the toolbar color to fill in the edges. 426 // Draw the toolbar color to fill in the edges.
487 canvas->DrawRectInt(ResourceBundle::toolbar_color, 427 canvas->DrawRectInt(ResourceBundle::toolbar_color,
488 client_area_bounds.x() - 1, client_area_top - 1, 428 client_area_bounds.x() - 1, client_area_top - 1,
489 client_area_bounds.width() + 1, client_area_bottom - client_area_top + 1); 429 client_area_bounds.width() + 1, client_area_bottom - client_area_top + 1);
490 } 430 }
491 431
432 SkColor CustomFrameView::GetFrameColor() const {
433 return frame_->IsActive() ?
434 ResourceBundle::frame_color :
435 ResourceBundle::frame_color_inactive;
436 }
437
438 SkBitmap* CustomFrameView::GetFrameBitmap() const {
439 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
440 frame_->IsActive() ? IDR_FRAME : IDR_FRAME_INACTIVE);
441 }
442
492 void CustomFrameView::LayoutWindowControls() { 443 void CustomFrameView::LayoutWindowControls() {
493 close_button_->SetImageAlignment(ImageButton::ALIGN_LEFT, 444 close_button_->SetImageAlignment(ImageButton::ALIGN_LEFT,
494 ImageButton::ALIGN_BOTTOM); 445 ImageButton::ALIGN_BOTTOM);
495 int caption_y = CaptionButtonY(); 446 int caption_y = CaptionButtonY();
496 bool is_maximized = frame_->IsMaximized(); 447 bool is_maximized = frame_->IsMaximized();
497 // There should always be the same number of non-shadow pixels visible to the 448 // There should always be the same number of non-shadow pixels visible to the
498 // side of the caption buttons. In maximized mode we extend the rightmost 449 // side of the caption buttons. In maximized mode we extend the rightmost
499 // button to the screen corner to obey Fitts' Law. 450 // button to the screen corner to obey Fitts' Law.
500 int right_extra_width = is_maximized ? 451 int right_extra_width = is_maximized ?
501 (kFrameBorderThickness - kFrameShadowThickness) : 0; 452 (kFrameBorderThickness - kFrameShadowThickness) : 0;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 title_font_ = new gfx::Font(NativeWidgetWin::GetWindowTitleFont()); 547 title_font_ = new gfx::Font(NativeWidgetWin::GetWindowTitleFont());
597 #elif defined(OS_LINUX) 548 #elif defined(OS_LINUX)
598 // TODO(ben): need to resolve what font this is. 549 // TODO(ben): need to resolve what font this is.
599 title_font_ = new gfx::Font(); 550 title_font_ = new gfx::Font();
600 #endif 551 #endif
601 initialized = true; 552 initialized = true;
602 } 553 }
603 } 554 }
604 555
605 } // namespace views 556 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/window/custom_frame_view.h ('k') | ui/views/window/frame_background.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698