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

Side by Side Diff: ash/frame/header_painter.cc

Issue 199283004: Fixes bugs wrt to painting window header (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | « ash/frame/header_painter.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ash/frame/header_painter.h" 5 #include "ash/frame/header_painter.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" 9 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
10 #include "base/logging.h" // DCHECK 10 #include "base/logging.h" // DCHECK
(...skipping 21 matching lines...) Expand all
32 // Space between left edge of window and popup window icon. 32 // Space between left edge of window and popup window icon.
33 const int kIconOffsetX = 9; 33 const int kIconOffsetX = 9;
34 // Height and width of window icon. 34 // Height and width of window icon.
35 const int kIconSize = 16; 35 const int kIconSize = 16;
36 // Space between the title text and the caption buttons. 36 // Space between the title text and the caption buttons.
37 const int kTitleLogoSpacing = 5; 37 const int kTitleLogoSpacing = 5;
38 // Space between window icon and title text. 38 // Space between window icon and title text.
39 const int kTitleIconOffsetX = 5; 39 const int kTitleIconOffsetX = 5;
40 // Space between window edge and title text, when there is no icon. 40 // Space between window edge and title text, when there is no icon.
41 const int kTitleNoIconOffsetX = 8; 41 const int kTitleNoIconOffsetX = 8;
42 // Color for the non-maximized window title text. 42 // Color for the non-browser window title text.
43 const SkColor kNonMaximizedWindowTitleTextColor = SkColorSetRGB(40, 40, 40); 43 const SkColor kWindowTitleTextColor = SkColorSetRGB(40, 40, 40);
44 // Color for the maximized window title text. 44 // Color for the non-maximized browser window title text.
45 const SkColor kMaximizedWindowTitleTextColor = SK_ColorWHITE; 45 const SkColor kNonMaximizedBrowserWindowTitleTextColor =
James Cook 2014/03/14 00:02:22 Would this be clearer as kRestoredBrowserWindowTit
pkotwicz 2014/03/14 14:48:45 Done.
46 SkColorSetRGB(40, 40, 40);
47 // Color for the maximized browser window title text.
48 const SkColor kMaximizedBrowserWindowTitleTextColor = SK_ColorWHITE;
46 // Size of header/content separator line below the header image for non-browser 49 // Size of header/content separator line below the header image for non-browser
47 // windows. 50 // windows.
48 const int kHeaderContentSeparatorSize = 1; 51 const int kHeaderContentSeparatorSize = 1;
49 // Color of the active window header/content separator line for non-browser 52 // Color of the active window header/content separator line for non-browser
50 // windows. 53 // windows.
51 const SkColor kHeaderContentSeparatorColor = SkColorSetRGB(180, 180, 182); 54 const SkColor kHeaderContentSeparatorColor = SkColorSetRGB(180, 180, 182);
52 // Color of the inactive window header/content separator line for non-browser 55 // Color of the inactive window header/content separator line for non-browser
53 // windows. 56 // windows.
54 const SkColor kHeaderContentSeparatorInactiveColor = 57 const SkColor kHeaderContentSeparatorInactiveColor =
55 SkColorSetRGB(150, 150, 152); 58 SkColorSetRGB(150, 150, 152);
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 theme_frame, 304 theme_frame,
302 theme_frame_overlay, 305 theme_frame_overlay,
303 paint, 306 paint,
304 GetHeaderLocalBounds(), 307 GetHeaderLocalBounds(),
305 corner_radius, 308 corner_radius,
306 GetThemeBackgroundXInset()); 309 GetThemeBackgroundXInset());
307 310
308 previous_theme_frame_id_ = theme_frame_id; 311 previous_theme_frame_id_ = theme_frame_id;
309 previous_theme_frame_overlay_id_ = theme_frame_overlay_id; 312 previous_theme_frame_overlay_id_ = theme_frame_overlay_id;
310 313
311 PaintBorder(canvas, mode); 314 if (!frame_->IsMaximized() && !frame_->IsFullscreen()) {
James Cook 2014/03/14 00:02:22 optional nit: Maybe early return to emphasize that
pkotwicz 2014/03/14 14:48:45 Keeping it this way makes the diff for the followu
315 if (style_ == STYLE_BROWSER) {
316 PaintHighlightForRestoredBrowserWindow(canvas);
317 } else {
318 if (mode == MODE_INACTIVE)
319 PaintHighlightForInactiveRestoredWindow(canvas);
320 }
321 }
312 } 322 }
313 323
314 void HeaderPainter::PaintHeaderContentSeparator(gfx::Canvas* canvas, 324 void HeaderPainter::PaintHeaderContentSeparator(gfx::Canvas* canvas,
315 Mode mode) { 325 Mode mode) {
316 DCHECK_EQ(style_, STYLE_OTHER); 326 DCHECK_EQ(style_, STYLE_OTHER);
317 SkColor color = (mode == MODE_ACTIVE) ? 327 SkColor color = (mode == MODE_ACTIVE) ?
318 kHeaderContentSeparatorColor : 328 kHeaderContentSeparatorColor :
319 kHeaderContentSeparatorInactiveColor; 329 kHeaderContentSeparatorInactiveColor;
320 330
321 canvas->FillRect(gfx::Rect(0, 331 canvas->FillRect(gfx::Rect(0,
322 header_height_ - kHeaderContentSeparatorSize, 332 header_height_ - kHeaderContentSeparatorSize,
323 header_view_->width(), 333 header_view_->width(),
324 kHeaderContentSeparatorSize), 334 kHeaderContentSeparatorSize),
325 color); 335 color);
326 } 336 }
327 337
328 int HeaderPainter::HeaderContentSeparatorSize() const { 338 int HeaderPainter::HeaderContentSeparatorSize() const {
329 return kHeaderContentSeparatorSize; 339 return kHeaderContentSeparatorSize;
330 } 340 }
331 341
332 void HeaderPainter::PaintTitleBar(gfx::Canvas* canvas, 342 void HeaderPainter::PaintTitleBar(gfx::Canvas* canvas,
333 const gfx::FontList& title_font_list) { 343 const gfx::FontList& title_font_list) {
334 // The window icon is painted by its own views::View. 344 // The window icon is painted by its own views::View.
335 views::WidgetDelegate* delegate = frame_->widget_delegate(); 345 views::WidgetDelegate* delegate = frame_->widget_delegate();
336 if (delegate && delegate->ShouldShowWindowTitle()) { 346 if (delegate && delegate->ShouldShowWindowTitle()) {
337 gfx::Rect title_bounds = GetTitleBounds(title_font_list); 347 gfx::Rect title_bounds = GetTitleBounds(title_font_list);
338 title_bounds.set_x(header_view_->GetMirroredXForRect(title_bounds)); 348 title_bounds.set_x(header_view_->GetMirroredXForRect(title_bounds));
339 SkColor title_color = (frame_->IsMaximized() || frame_->IsFullscreen()) ? 349 SkColor title_color = kWindowTitleTextColor;
340 kMaximizedWindowTitleTextColor : kNonMaximizedWindowTitleTextColor; 350 if (style_ == STYLE_BROWSER) {
351 title_color = (frame_->IsMaximized() || frame_->IsFullscreen()) ?
352 kMaximizedBrowserWindowTitleTextColor :
353 kNonMaximizedBrowserWindowTitleTextColor;
354 }
341 canvas->DrawStringRectWithFlags(delegate->GetWindowTitle(), 355 canvas->DrawStringRectWithFlags(delegate->GetWindowTitle(),
342 title_font_list, 356 title_font_list,
343 title_color, 357 title_color,
344 title_bounds, 358 title_bounds,
345 gfx::Canvas::NO_SUBPIXEL_RENDERING); 359 gfx::Canvas::NO_SUBPIXEL_RENDERING);
346 } 360 }
347 } 361 }
348 362
349 void HeaderPainter::LayoutHeader() { 363 void HeaderPainter::LayoutHeader() {
350 // Purposefully set |header_height_| to an invalid value. We cannot use 364 // Purposefully set |header_height_| to an invalid value. We cannot use
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 /////////////////////////////////////////////////////////////////////////////// 409 ///////////////////////////////////////////////////////////////////////////////
396 // gfx::AnimationDelegate overrides: 410 // gfx::AnimationDelegate overrides:
397 411
398 void HeaderPainter::AnimationProgressed(const gfx::Animation* animation) { 412 void HeaderPainter::AnimationProgressed(const gfx::Animation* animation) {
399 header_view_->SchedulePaintInRect(GetHeaderLocalBounds()); 413 header_view_->SchedulePaintInRect(GetHeaderLocalBounds());
400 } 414 }
401 415
402 /////////////////////////////////////////////////////////////////////////////// 416 ///////////////////////////////////////////////////////////////////////////////
403 // HeaderPainter, private: 417 // HeaderPainter, private:
404 418
405 void HeaderPainter::PaintBorder(gfx::Canvas* canvas, Mode mode) { 419 void HeaderPainter::PaintHighlightForRestoredBrowserWindow(
406 if (frame_->IsMaximized() || 420 gfx::Canvas* canvas) {
407 frame_->IsFullscreen() ||
408 (style_ == STYLE_OTHER && mode == MODE_ACTIVE)) {
409 return;
410 }
411
412 gfx::ImageSkia top_left_corner;
413 gfx::ImageSkia top_right_corner;
414 gfx::ImageSkia top_edge;
415 gfx::ImageSkia left_edge;
416 gfx::ImageSkia right_edge;
417 gfx::ImageSkia bottom_edge;
418
419 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 421 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
420 if (style_ == STYLE_BROWSER) { 422 gfx::ImageSkia top_left_corner = *rb.GetImageSkiaNamed(
421 top_left_corner = *rb.GetImageSkiaNamed( 423 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP_LEFT);
422 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP_LEFT); 424 gfx::ImageSkia top_right_corner = *rb.GetImageSkiaNamed(
423 top_right_corner = *rb.GetImageSkiaNamed( 425 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP_RIGHT);
424 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP_RIGHT); 426 gfx::ImageSkia top_edge = *rb.GetImageSkiaNamed(
425 top_edge = *rb.GetImageSkiaNamed(IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP); 427 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_TOP);
426 left_edge = *rb.GetImageSkiaNamed( 428 gfx::ImageSkia left_edge = *rb.GetImageSkiaNamed(
427 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_LEFT); 429 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_LEFT);
428 right_edge = *rb.GetImageSkiaNamed( 430 gfx::ImageSkia right_edge = *rb.GetImageSkiaNamed(
429 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_RIGHT); 431 IDR_AURA_BROWSER_WINDOW_HEADER_SHADE_RIGHT);
430 } else {
431 top_edge = *rb.GetImageSkiaNamed(
432 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_TOP);
433 left_edge = *rb.GetImageSkiaNamed(
434 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_LEFT);
435 right_edge = *rb.GetImageSkiaNamed(
436 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_RIGHT);
437 bottom_edge = *rb.GetImageSkiaNamed(
438 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_BOTTOM);
439 }
440
441 DCHECK(!top_edge.isNull());
442 DCHECK(!left_edge.isNull());
443 DCHECK(!right_edge.isNull());
444 432
445 int top_left_width = top_left_corner.width(); 433 int top_left_width = top_left_corner.width();
446 int top_left_height = top_left_corner.height(); 434 int top_left_height = top_left_corner.height();
447 if (!top_left_corner.isNull()) { 435 canvas->DrawImageInt(top_left_corner, 0, 0);
448 canvas->DrawImageInt(top_left_corner, 0, 0);
449 }
450 436
437 int top_right_width = top_right_corner.width();
451 int top_right_height = top_right_corner.height(); 438 int top_right_height = top_right_corner.height();
452 if (!top_right_corner.isNull()) { 439 canvas->DrawImageInt(top_right_corner,
453 canvas->DrawImageInt(top_right_corner, 440 header_view_->width() - top_right_width,
454 header_view_->width() - top_right_corner.width(), 441 0);
455 top_right_height);
pkotwicz 2014/03/13 23:20:49 The y coordinate should be 0
456 }
457 442
458 canvas->TileImageInt(top_edge, 443 canvas->TileImageInt(
444 top_edge,
459 top_left_width, 445 top_left_width,
460 0, 446 0,
461 header_view_->width() - top_left_width - top_right_corner.width(), 447 header_view_->width() - top_left_width - top_right_width,
462 top_edge.height()); 448 top_edge.height());
463 449
464 // TODO(pkotwicz): Compute |bottom| more accurately. The computation is 450 canvas->TileImageInt(left_edge,
465 // inaccurate for browser windows. 451 0,
466 int bottom = header_height_ - kHeaderContentSeparatorSize; 452 top_left_height,
467 int bottom_height = bottom_edge.height(); 453 left_edge.width(),
468 if (!bottom_edge.isNull()) { 454 header_height_ - top_left_height);
469 canvas->TileImageInt(bottom_edge,
470 0, bottom - bottom_height,
471 header_view_->width(), bottom_height);
472 }
473 455
474 int left_edge_height = bottom - bottom_height - top_left_height;
475 canvas->TileImageInt(left_edge,
476 0, top_left_height,
477 left_edge.width(), left_edge_height);
478
479 int right_edge_height = bottom - bottom_height - top_right_height;
480 canvas->TileImageInt(right_edge, 456 canvas->TileImageInt(right_edge,
481 header_view_->width() - right_edge.width(), 457 header_view_->width() - right_edge.width(),
482 top_right_height, 458 top_right_height,
483 right_edge.width(), 459 right_edge.width(),
484 right_edge_height); 460 header_height_ - top_right_height);
461 }
462
463 void HeaderPainter::PaintHighlightForInactiveRestoredWindow(
464 gfx::Canvas* canvas) {
465 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
466 gfx::ImageSkia top_edge = *rb.GetImageSkiaNamed(
467 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_TOP);
468 gfx::ImageSkia left_edge = *rb.GetImageSkiaNamed(
469 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_LEFT);
470 gfx::ImageSkia right_edge = *rb.GetImageSkiaNamed(
471 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_RIGHT);
472 gfx::ImageSkia bottom_edge = *rb.GetImageSkiaNamed(
473 IDR_AURA_WINDOW_HEADER_SHADE_INACTIVE_BOTTOM);
474
pkotwicz 2014/03/13 23:20:49 The left and right images are flush with the top h
475 int left_edge_width = left_edge.width();
476 int right_edge_width = right_edge.width();
477 canvas->DrawImageInt(left_edge, 0, 0);
478 canvas->DrawImageInt(right_edge, header_view_->width() - right_edge_width, 0);
479 canvas->TileImageInt(
480 top_edge,
481 left_edge_width,
482 0,
483 header_view_->width() - left_edge_width - right_edge_width,
484 top_edge.height());
485
486 DCHECK_EQ(left_edge.height(), right_edge.height());
487 int bottom = left_edge.height();
488 int bottom_height = bottom_edge.height();
489 canvas->TileImageInt(
490 bottom_edge,
491 left_edge_width,
492 bottom - bottom_height,
493 header_view_->width() - left_edge_width - right_edge_width,
494 bottom_height);
485 } 495 }
486 496
487 void HeaderPainter::UpdateCaptionButtonImages() { 497 void HeaderPainter::UpdateCaptionButtonImages() {
488 if (style_ == STYLE_BROWSER) { 498 if (style_ == STYLE_BROWSER) {
489 if (frame_->IsMaximized() || frame_->IsFullscreen()) { 499 if (frame_->IsMaximized() || frame_->IsFullscreen()) {
490 caption_button_container_->SetButtonImages( 500 caption_button_container_->SetButtonImages(
491 CAPTION_BUTTON_ICON_MINIMIZE, 501 CAPTION_BUTTON_ICON_MINIMIZE,
492 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_MINIMIZE, 502 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_MINIMIZE,
493 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_MINIMIZE, 503 IDR_AURA_BROWSER_WINDOW_CONTROL_ICON_MAXIMIZED_MINIMIZE,
494 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H, 504 IDR_AURA_BROWSER_WINDOW_CONTROL_BACKGROUND_MAXIMIZED_H,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 int title_y = 626 int title_y =
617 GetCaptionButtonContainerCenterY() - title_font_list.GetHeight() / 2; 627 GetCaptionButtonContainerCenterY() - title_font_list.GetHeight() / 2;
618 return gfx::Rect( 628 return gfx::Rect(
619 title_x, 629 title_x,
620 std::max(0, title_y), 630 std::max(0, title_y),
621 std::max(0, caption_button_container_->x() - kTitleLogoSpacing - title_x), 631 std::max(0, caption_button_container_->x() - kTitleLogoSpacing - title_x),
622 title_font_list.GetHeight()); 632 title_font_list.GetHeight());
623 } 633 }
624 634
625 } // namespace ash 635 } // namespace ash
OLDNEW
« no previous file with comments | « ash/frame/header_painter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698