OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/browser/views/detachable_toolbar_view.h" | 5 #include "chrome/browser/views/detachable_toolbar_view.h" |
6 | 6 |
7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "chrome/browser/browser_theme_provider.h" | 8 #include "chrome/browser/browser_theme_provider.h" |
9 #include "gfx/canvas_skia.h" | 9 #include "gfx/canvas_skia.h" |
10 #include "gfx/skia_util.h" | 10 #include "gfx/skia_util.h" |
11 #include "grit/theme_resources.h" | 11 #include "grit/theme_resources.h" |
12 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
13 #include "third_party/skia/include/core/SkShader.h" | 13 #include "third_party/skia/include/core/SkShader.h" |
| 14 #include "views/window/non_client_view.h" |
14 | 15 |
15 // How round the 'new tab' style bookmarks bar is. | 16 // How round the 'new tab' style bookmarks bar is. |
16 static const int kNewtabBarRoundness = 5; | 17 static const int kNewtabBarRoundness = 5; |
17 | 18 |
18 const SkColor DetachableToolbarView::kEdgeDividerColor = | 19 const SkColor DetachableToolbarView::kEdgeDividerColor = |
19 SkColorSetRGB(222, 234, 248); | 20 SkColorSetRGB(222, 234, 248); |
20 const SkColor DetachableToolbarView::kMiddleDividerColor = | 21 const SkColor DetachableToolbarView::kMiddleDividerColor = |
21 SkColorSetRGB(194, 205, 212); | 22 SkColorSetRGB(194, 205, 212); |
22 | 23 |
23 // static | 24 // static |
24 void DetachableToolbarView::PaintBackgroundAttachedMode(gfx::Canvas* canvas, | 25 void DetachableToolbarView::PaintBackgroundAttachedMode( |
25 views::View* view) { | 26 gfx::Canvas* canvas, |
26 gfx::Rect bounds = | 27 views::View* view, |
27 view->GetBounds(views::View::APPLY_MIRRORING_TRANSFORMATION); | 28 const gfx::Point& background_origin) { |
28 | |
29 ThemeProvider* tp = view->GetThemeProvider(); | 29 ThemeProvider* tp = view->GetThemeProvider(); |
30 SkColor theme_toolbar_color = | 30 SkColor theme_toolbar_color = |
31 tp->GetColor(BrowserThemeProvider::COLOR_TOOLBAR); | 31 tp->GetColor(BrowserThemeProvider::COLOR_TOOLBAR); |
32 canvas->FillRectInt(theme_toolbar_color, 0, 0, | 32 canvas->FillRectInt(theme_toolbar_color, 0, 0, |
33 view->width(), view->height()); | 33 view->width(), view->height()); |
34 | |
35 canvas->TileImageInt(*tp->GetBitmapNamed(IDR_THEME_TOOLBAR), | 34 canvas->TileImageInt(*tp->GetBitmapNamed(IDR_THEME_TOOLBAR), |
36 view->GetParent()->GetBounds( | 35 background_origin.x(), background_origin.y(), 0, 0, |
37 views::View::APPLY_MIRRORING_TRANSFORMATION).x() + bounds.x(), | 36 view->width(), view->height()); |
38 bounds.y(), 0, 0, view->width(), view->height()); | |
39 } | 37 } |
40 | 38 |
41 // static | 39 // static |
42 void DetachableToolbarView::CalculateContentArea( | 40 void DetachableToolbarView::CalculateContentArea( |
43 double animation_state, double horizontal_padding, | 41 double animation_state, double horizontal_padding, |
44 double vertical_padding, SkRect* rect, | 42 double vertical_padding, SkRect* rect, |
45 double* roundness, views::View* view) { | 43 double* roundness, views::View* view) { |
46 // The 0.5 is to correct for Skia's "draw on pixel boundaries"ness. | 44 // The 0.5 is to correct for Skia's "draw on pixel boundaries"ness. |
47 rect->set(SkDoubleToScalar(horizontal_padding - 0.5), | 45 rect->set(SkDoubleToScalar(horizontal_padding - 0.5), |
48 SkDoubleToScalar(vertical_padding - 0.5), | 46 SkDoubleToScalar(vertical_padding - 0.5), |
49 SkDoubleToScalar(view->width() - horizontal_padding - 0.5), | 47 SkDoubleToScalar(view->width() - horizontal_padding - 0.5), |
50 SkDoubleToScalar(view->height() - vertical_padding - 0.5)); | 48 SkDoubleToScalar(view->height() - vertical_padding - 0.5)); |
51 | 49 |
52 *roundness = static_cast<double>(kNewtabBarRoundness) * animation_state; | 50 *roundness = static_cast<double>(kNewtabBarRoundness) * animation_state; |
53 } | 51 } |
54 | 52 |
55 // static | 53 // static |
56 void DetachableToolbarView::PaintHorizontalBorder(gfx::Canvas* canvas, | 54 void DetachableToolbarView::PaintHorizontalBorder(gfx::Canvas* canvas, |
57 DetachableToolbarView* view) { | 55 DetachableToolbarView* view) { |
58 // Border can be at the top or at the bottom of the view depending on whether | 56 // Border can be at the top or at the bottom of the view depending on whether |
59 // the view (bar/shelf) is attached or detached. | 57 // the view (bar/shelf) is attached or detached. |
60 int y = !view->IsDetached() ? view->height() - 1 : 0; | 58 int thickness = views::NonClientFrameView::kClientEdgeThickness; |
| 59 int y = view->IsDetached() ? 0 : (view->height() - thickness); |
61 canvas->FillRectInt(ResourceBundle::toolbar_separator_color, | 60 canvas->FillRectInt(ResourceBundle::toolbar_separator_color, |
62 0, y, view->width(), 1); | 61 0, y, view->width(), thickness); |
63 } | 62 } |
64 | 63 |
65 // static | 64 // static |
66 void DetachableToolbarView::PaintContentAreaBackground( | 65 void DetachableToolbarView::PaintContentAreaBackground( |
67 gfx::Canvas* canvas, ThemeProvider* theme_provider, | 66 gfx::Canvas* canvas, ThemeProvider* theme_provider, |
68 const SkRect& rect, double roundness) { | 67 const SkRect& rect, double roundness) { |
69 SkPaint paint; | 68 SkPaint paint; |
70 paint.setAntiAlias(true); | 69 paint.setAntiAlias(true); |
71 paint.setColor(theme_provider->GetColor(BrowserThemeProvider::COLOR_TOOLBAR)); | 70 paint.setColor(theme_provider->GetColor(BrowserThemeProvider::COLOR_TOOLBAR)); |
72 | 71 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 paint_down.setShader(gfx::CreateGradientShader(height / 2, | 112 paint_down.setShader(gfx::CreateGradientShader(height / 2, |
114 height - vertical_padding, | 113 height - vertical_padding, |
115 middle_color, | 114 middle_color, |
116 bottom_color))->safeUnref(); | 115 bottom_color))->safeUnref(); |
117 SkRect rc_down = { SkIntToScalar(x), | 116 SkRect rc_down = { SkIntToScalar(x), |
118 SkIntToScalar(height / 2), | 117 SkIntToScalar(height / 2), |
119 SkIntToScalar(x + 1), | 118 SkIntToScalar(x + 1), |
120 SkIntToScalar(height - vertical_padding) }; | 119 SkIntToScalar(height - vertical_padding) }; |
121 canvas->AsCanvasSkia()->drawRect(rc_down, paint_down); | 120 canvas->AsCanvasSkia()->drawRect(rc_down, paint_down); |
122 } | 121 } |
OLD | NEW |