1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/ui/views/detachable_toolbar_view.h" 6 7 #include "chrome/browser/themes/theme_properties.h" 8 #include "grit/theme_resources.h" 9 #include "third_party/skia/include/core/SkShader.h" 10 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/theme_provider.h" 12 #include "ui/gfx/canvas.h" 13 #include "ui/gfx/image/image_skia.h" 14 #include "ui/gfx/skia_util.h" 15 #include "ui/views/window/non_client_view.h" 16 17 // How round the 'new tab' style bookmarks bar is. 18 static const int kNewtabBarRoundness = 5; 19 20 const SkColor DetachableToolbarView::kEdgeDividerColor = 21 SkColorSetRGB(222, 234, 248); 22 const SkColor DetachableToolbarView::kMiddleDividerColor = 23 SkColorSetRGB(194, 205, 212); 24 25 // static 26 void DetachableToolbarView::PaintBackgroundAttachedMode( 27 gfx::Canvas* canvas, 28 ui::ThemeProvider* theme_provider, 29 const gfx::Rect& bounds, 30 const gfx::Point& background_origin, 31 chrome::HostDesktopType host_desktop_type) { 32 canvas->FillRect(bounds, 33 theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR)); 34 canvas->TileImageInt(*theme_provider->GetImageSkiaNamed(IDR_THEME_TOOLBAR), 35 background_origin.x(), background_origin.y(), bounds.x(), 36 bounds.y(), bounds.width(), bounds.height()); 37 38 if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH) { 39 // Ash provides additional lightening at the edges of the toolbar. 40 gfx::ImageSkia* toolbar_left = 41 theme_provider->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_LEFT); 42 canvas->TileImageInt(*toolbar_left, 43 bounds.x(), bounds.y(), 44 toolbar_left->width(), bounds.height()); 45 gfx::ImageSkia* toolbar_right = 46 theme_provider->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT); 47 canvas->TileImageInt(*toolbar_right, 48 bounds.right() - toolbar_right->width(), bounds.y(), 49 toolbar_right->width(), bounds.height()); 50 } 51 } 52 53 // static 54 void DetachableToolbarView::CalculateContentArea( 55 double animation_state, double horizontal_padding, 56 double vertical_padding, SkRect* rect, 57 double* roundness, views::View* view) { 58 // The 0.5 is to correct for Skia's "draw on pixel boundaries"ness. 59 rect->set(SkDoubleToScalar(horizontal_padding - 0.5), 60 SkDoubleToScalar(vertical_padding - 0.5), 61 SkDoubleToScalar(view->width() - horizontal_padding - 0.5), 62 SkDoubleToScalar(view->height() - vertical_padding - 0.5)); 63 64 *roundness = static_cast<double>(kNewtabBarRoundness) * animation_state; 65 } 66 67 // static 68 void DetachableToolbarView::PaintHorizontalBorder( 69 gfx::Canvas* canvas, 70 DetachableToolbarView* view, 71 bool at_top, 72 SkColor color) { 73 int thickness = views::NonClientFrameView::kClientEdgeThickness; 74 int y = at_top ? 0 : (view->height() - thickness); 75 canvas->FillRect(gfx::Rect(0, y, view->width(), thickness), color); 76 } 77 78 // static 79 void DetachableToolbarView::PaintContentAreaBackground( 80 gfx::Canvas* canvas, 81 ui::ThemeProvider* theme_provider, 82 const SkRect& rect, 83 double roundness) { 84 SkPaint paint; 85 paint.setAntiAlias(true); 86 paint.setColor(theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR)); 87 88 canvas->sk_canvas()->drawRoundRect( 89 rect, SkDoubleToScalar(roundness), SkDoubleToScalar(roundness), paint); 90 } 91 92 // static 93 void DetachableToolbarView::PaintContentAreaBorder( 94 gfx::Canvas* canvas, ui::ThemeProvider* theme_provider, 95 const SkRect& rect, double roundness) { 96 SkPaint border_paint; 97 border_paint.setColor( 98 theme_provider->GetColor(ThemeProperties::COLOR_NTP_HEADER)); 99 border_paint.setStyle(SkPaint::kStroke_Style); 100 border_paint.setAlpha(96); 101 border_paint.setAntiAlias(true); 102 103 canvas->sk_canvas()->drawRoundRect( 104 rect, SkDoubleToScalar(roundness), SkDoubleToScalar(roundness), 105 border_paint); 106 } 107 108 // static 109 void DetachableToolbarView::PaintVerticalDivider(gfx::Canvas* canvas, 110 int x, 111 int height, 112 int vertical_padding, 113 SkColor top_color, 114 SkColor middle_color, 115 SkColor bottom_color) { 116 // Draw the upper half of the divider. 117 SkPaint paint; 118 skia::RefPtr<SkShader> shader = gfx::CreateGradientShader( 119 vertical_padding + 1, height / 2, top_color, middle_color); 120 paint.setShader(shader.get()); 121 SkRect rc = { SkIntToScalar(x), 122 SkIntToScalar(vertical_padding + 1), 123 SkIntToScalar(x + 1), 124 SkIntToScalar(height / 2) }; 125 canvas->sk_canvas()->drawRect(rc, paint); 126 127 // Draw the lower half of the divider. 128 SkPaint paint_down; 129 shader = gfx::CreateGradientShader( 130 height / 2, height - vertical_padding, middle_color, bottom_color); 131 paint_down.setShader(shader.get()); 132 SkRect rc_down = { SkIntToScalar(x), 133 SkIntToScalar(height / 2), 134 SkIntToScalar(x + 1), 135 SkIntToScalar(height - vertical_padding) }; 136 canvas->sk_canvas()->drawRect(rc_down, paint_down); 137 } 138