OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/ui/views/frame/browser_frame_aura.h" | 5 #include "chrome/browser/ui/views/frame/browser_frame_aura.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "chrome/browser/chromeos/status/status_area_view.h" | 10 #include "chrome/browser/chromeos/status/status_area_view.h" |
11 #include "chrome/browser/themes/theme_service.h" | |
12 #include "chrome/browser/ui/views/ash/chrome_shell_delegate.h" | 11 #include "chrome/browser/ui/views/ash/chrome_shell_delegate.h" |
13 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_aura.h" | |
14 #include "chrome/browser/ui/views/frame/browser_view.h" | 12 #include "chrome/browser/ui/views/frame/browser_view.h" |
15 #include "grit/theme_resources_standard.h" | |
16 #include "third_party/skia/include/core/SkBitmap.h" | |
17 #include "third_party/skia/include/core/SkCanvas.h" | |
18 #include "third_party/skia/include/core/SkColor.h" | |
19 #include "ui/aura/client/aura_constants.h" | 13 #include "ui/aura/client/aura_constants.h" |
20 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
21 #include "ui/aura/window_observer.h" | 15 #include "ui/aura/window_observer.h" |
22 #include "ui/base/theme_provider.h" | |
23 #include "ui/gfx/canvas.h" | |
24 #include "ui/gfx/compositor/layer.h" | |
25 #include "ui/gfx/font.h" | 16 #include "ui/gfx/font.h" |
26 #include "ui/views/background.h" | 17 #include "ui/views/background.h" |
27 | 18 |
28 namespace { | 19 namespace { |
29 | 20 |
30 // The content left/right images have a shadow built into them. | |
31 const int kContentEdgeShadowThickness = 2; | |
32 | |
33 // Background view to paint the gradient behind the back/forward/omnibox | |
34 // toolbar area. | |
35 class ToolbarBackground : public views::Background { | |
36 public: | |
37 explicit ToolbarBackground(BrowserView* browser_view); | |
38 virtual ~ToolbarBackground(); | |
39 | |
40 // views::Background overrides: | |
41 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE; | |
42 | |
43 private: | |
44 BrowserView* browser_view_; | |
45 DISALLOW_COPY_AND_ASSIGN(ToolbarBackground); | |
46 }; | |
47 | |
48 ToolbarBackground::ToolbarBackground(BrowserView* browser_view) | |
49 : browser_view_(browser_view) { | |
50 } | |
51 | |
52 ToolbarBackground::~ToolbarBackground() { | |
53 } | |
54 | |
55 void ToolbarBackground::Paint(gfx::Canvas* canvas, views::View* view) const { | |
56 gfx::Rect toolbar_bounds = browser_view_->GetToolbarBounds(); | |
57 if (toolbar_bounds.IsEmpty()) | |
58 return; | |
59 | |
60 int x = toolbar_bounds.x(); | |
61 int w = toolbar_bounds.width(); | |
62 int y = toolbar_bounds.y(); | |
63 int h = toolbar_bounds.bottom(); | |
64 | |
65 // Gross hack: We split the toolbar images into two pieces, since sometimes | |
66 // (popup mode) the toolbar isn't tall enough to show the whole image. The | |
67 // split happens between the top shadow section and the bottom gradient | |
68 // section so that we never break the gradient. | |
69 int split_point = views::NonClientFrameView::kFrameShadowThickness * 2; | |
70 int bottom_y = y + split_point; | |
71 ui::ThemeProvider* tp = browser_view_->GetThemeProvider(); | |
72 SkBitmap* toolbar_left = tp->GetBitmapNamed(IDR_CONTENT_TOP_LEFT_CORNER); | |
73 int bottom_edge_height = std::min(toolbar_left->height(), h) - split_point; | |
74 | |
75 canvas->FillRect(gfx::Rect(x, bottom_y, w, bottom_edge_height), | |
76 tp->GetColor(ThemeService::COLOR_TOOLBAR)); | |
77 | |
78 // Tile the toolbar image starting at the frame edge on the left and where the | |
79 // horizontal tabstrip is (or would be) on the top. | |
80 SkBitmap* theme_toolbar = tp->GetBitmapNamed(IDR_THEME_TOOLBAR); | |
81 canvas->TileImageInt(*theme_toolbar, | |
82 x, bottom_y, | |
83 x, bottom_y, | |
84 w, theme_toolbar->height()); | |
85 | |
86 SkBitmap* toolbar_center = | |
87 tp->GetBitmapNamed(IDR_CONTENT_TOP_CENTER); | |
88 canvas->TileImageInt(*toolbar_center, | |
89 0, 0, | |
90 x, y, | |
91 w, split_point); | |
92 | |
93 // Draw the content/toolbar separator. | |
94 canvas->FillRect(gfx::Rect( | |
95 x + views::NonClientFrameView::kClientEdgeThickness, | |
96 toolbar_bounds.bottom() - views::NonClientFrameView::kClientEdgeThickness, | |
97 w - (2 * views::NonClientFrameView::kClientEdgeThickness), | |
98 views::NonClientFrameView::kClientEdgeThickness), | |
99 ThemeService::GetDefaultColor(ThemeService::COLOR_TOOLBAR_SEPARATOR)); | |
100 } | |
101 | |
102 //////////////////////////////////////////////////////////////////////////////// | 21 //////////////////////////////////////////////////////////////////////////////// |
103 // StatusAreaBoundsWatcher | 22 // StatusAreaBoundsWatcher |
104 | 23 |
105 class StatusAreaBoundsWatcher : public aura::WindowObserver { | 24 class StatusAreaBoundsWatcher : public aura::WindowObserver { |
106 public: | 25 public: |
107 explicit StatusAreaBoundsWatcher(BrowserFrame* frame) | 26 explicit StatusAreaBoundsWatcher(BrowserFrame* frame) |
108 : frame_(frame), | 27 : frame_(frame), |
109 status_area_window_(NULL) { | 28 status_area_window_(NULL) { |
110 StartWatch(); | 29 StartWatch(); |
111 } | 30 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 }; | 124 }; |
206 | 125 |
207 /////////////////////////////////////////////////////////////////////////////// | 126 /////////////////////////////////////////////////////////////////////////////// |
208 // BrowserFrameAura, public: | 127 // BrowserFrameAura, public: |
209 | 128 |
210 BrowserFrameAura::BrowserFrameAura(BrowserFrame* browser_frame, | 129 BrowserFrameAura::BrowserFrameAura(BrowserFrame* browser_frame, |
211 BrowserView* browser_view) | 130 BrowserView* browser_view) |
212 : views::NativeWidgetAura(browser_frame), | 131 : views::NativeWidgetAura(browser_frame), |
213 browser_view_(browser_view), | 132 browser_view_(browser_view), |
214 window_property_watcher_(new WindowPropertyWatcher(this, browser_frame)) { | 133 window_property_watcher_(new WindowPropertyWatcher(this, browser_frame)) { |
215 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
216 if (command_line->HasSwitch(ash::switches::kAuraTranslucentFrames)) { | |
217 // Background only needed for Aura-style windows. | |
218 browser_view_->set_background(new ToolbarBackground(browser_view)); | |
219 } | |
220 GetNativeWindow()->SetName("BrowserFrameAura"); | 134 GetNativeWindow()->SetName("BrowserFrameAura"); |
221 GetNativeWindow()->AddObserver(window_property_watcher_.get()); | 135 GetNativeWindow()->AddObserver(window_property_watcher_.get()); |
222 } | 136 } |
223 | 137 |
224 BrowserFrameAura::~BrowserFrameAura() { | 138 BrowserFrameAura::~BrowserFrameAura() { |
225 } | 139 } |
226 | 140 |
227 /////////////////////////////////////////////////////////////////////////////// | 141 /////////////////////////////////////////////////////////////////////////////// |
228 // BrowserFrameAura, views::NativeWidgetAura overrides: | 142 // BrowserFrameAura, views::NativeWidgetAura overrides: |
229 | 143 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 | 177 |
264 //////////////////////////////////////////////////////////////////////////////// | 178 //////////////////////////////////////////////////////////////////////////////// |
265 // NativeBrowserFrame, public: | 179 // NativeBrowserFrame, public: |
266 | 180 |
267 // static | 181 // static |
268 NativeBrowserFrame* NativeBrowserFrame::CreateNativeBrowserFrame( | 182 NativeBrowserFrame* NativeBrowserFrame::CreateNativeBrowserFrame( |
269 BrowserFrame* browser_frame, | 183 BrowserFrame* browser_frame, |
270 BrowserView* browser_view) { | 184 BrowserView* browser_view) { |
271 return new BrowserFrameAura(browser_frame, browser_view); | 185 return new BrowserFrameAura(browser_frame, browser_view); |
272 } | 186 } |
OLD | NEW |