| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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_view.h" | 5 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 // or page content according to |at_top| with |color|. | 212 // or page content according to |at_top| with |color|. |
| 213 void PaintHorizontalBorder(gfx::Canvas* canvas, | 213 void PaintHorizontalBorder(gfx::Canvas* canvas, |
| 214 BookmarkBarView* view, | 214 BookmarkBarView* view, |
| 215 bool at_top, | 215 bool at_top, |
| 216 SkColor color) { | 216 SkColor color) { |
| 217 int thickness = views::NonClientFrameView::kClientEdgeThickness; | 217 int thickness = views::NonClientFrameView::kClientEdgeThickness; |
| 218 int y = at_top ? 0 : (view->height() - thickness); | 218 int y = at_top ? 0 : (view->height() - thickness); |
| 219 canvas->FillRect(gfx::Rect(0, y, view->width(), thickness), color); | 219 canvas->FillRect(gfx::Rect(0, y, view->width(), thickness), color); |
| 220 } | 220 } |
| 221 | 221 |
| 222 // TODO(kuan): These functions are temporarily for the bookmark bar while its | |
| 223 // detached state is at the top of the page; it'll be moved to float on the | |
| 224 // content page in the very near future, at which time, these local functions | |
| 225 // will be removed. | |
| 226 void PaintDetachedBookmarkBar(gfx::Canvas* canvas, | 222 void PaintDetachedBookmarkBar(gfx::Canvas* canvas, |
| 227 BookmarkBarView* view, | 223 BookmarkBarView* view) { |
| 228 Profile* profile) { | |
| 229 // Paint background for detached state; if animating, this is fade in/out. | 224 // Paint background for detached state; if animating, this is fade in/out. |
| 230 const ui::ThemeProvider& tp = | 225 const ui::ThemeProvider* tp = view->GetThemeProvider(); |
| 231 ThemeService::GetThemeProviderForProfile(profile); | 226 // In detached mode, the bar is meant to overlap with |contents_container_|. |
| 227 // Since the layer for |view| is opaque, we have to recreate that base color |
| 228 // here. (The detached background color may be partially transparent.) |
| 232 canvas->DrawColor( | 229 canvas->DrawColor( |
| 233 tp.GetColor(ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_BACKGROUND)); | 230 tp->GetColor(ThemeProperties::COLOR_CONTROL_BACKGROUND)); |
| 231 canvas->DrawColor( |
| 232 tp->GetColor(ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_BACKGROUND)); |
| 233 |
| 234 // Draw the separators above and below bookmark bar; | 234 // Draw the separators above and below bookmark bar; |
| 235 // if animating, these are fading in/out. | 235 // if animating, these are fading in/out. |
| 236 SkColor separator_color = | 236 SkColor separator_color = |
| 237 tp.GetColor(ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_SEPARATOR); | 237 tp->GetColor(ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_SEPARATOR); |
| 238 | 238 |
| 239 if (ui::MaterialDesignController::IsModeMaterial()) { | 239 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 240 BrowserView::Paint1pxHorizontalLine( | 240 BrowserView::Paint1pxHorizontalLine( |
| 241 canvas, separator_color, | 241 canvas, separator_color, |
| 242 gfx::Rect(0, 0, view->width(), | 242 gfx::Rect(0, 0, view->width(), |
| 243 views::NonClientFrameView::kClientEdgeThickness), | 243 views::NonClientFrameView::kClientEdgeThickness), |
| 244 true); | 244 true); |
| 245 } else { | 245 } else { |
| 246 PaintHorizontalBorder(canvas, view, true, separator_color); | 246 PaintHorizontalBorder(canvas, view, true, separator_color); |
| 247 } | 247 } |
| 248 | 248 |
| 249 // For the bottom separator, increase the luminance. Either double it or halve | 249 // For the bottom separator, increase the luminance. Either double it or halve |
| 250 // the distance to 1.0, whichever is less of a difference. | 250 // the distance to 1.0, whichever is less of a difference. |
| 251 color_utils::HSL hsl; | 251 color_utils::HSL hsl; |
| 252 color_utils::SkColorToHSL(separator_color, &hsl); | 252 color_utils::SkColorToHSL(separator_color, &hsl); |
| 253 hsl.l = std::min((hsl.l + 1) / 2, hsl.l * 2); | 253 hsl.l = std::min((hsl.l + 1) / 2, hsl.l * 2); |
| 254 BrowserView::Paint1pxHorizontalLine( | 254 BrowserView::Paint1pxHorizontalLine( |
| 255 canvas, color_utils::HSLToSkColor(hsl, SK_AlphaOPAQUE), | 255 canvas, color_utils::HSLToSkColor(hsl, SK_AlphaOPAQUE), |
| 256 view->GetLocalBounds(), true); | 256 view->GetLocalBounds(), true); |
| 257 } | 257 } |
| 258 | 258 |
| 259 // Paints the background (including the theme image behind content area) for | 259 // Paints the background (including the theme image behind content area) for |
| 260 // the Bookmarks Bar when it is attached to the Toolbar into |bounds|. | 260 // the Bookmarks Bar when it is attached to the Toolbar into |bounds|. |
| 261 // |background_origin| is the origin to use for painting the theme image. | 261 // |background_origin| is the origin to use for painting the theme image. |
| 262 void PaintBackgroundAttachedMode(gfx::Canvas* canvas, | 262 void PaintBackgroundAttachedMode(gfx::Canvas* canvas, |
| 263 const ui::ThemeProvider* theme_provider, | 263 const ui::ThemeProvider* theme_provider, |
| 264 const gfx::Rect& bounds, | 264 const gfx::Rect& bounds, |
| 265 const gfx::Point& background_origin) { | 265 const gfx::Point& background_origin) { |
| 266 canvas->FillRect(bounds, | 266 canvas->DrawColor(theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR)); |
| 267 theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR)); | |
| 268 | 267 |
| 269 // Always tile the background image in pre-MD. In MD, only tile if there's a | 268 // Always tile the background image in pre-MD. In MD, only tile if there's a |
| 270 // non-default image. | 269 // non-default image. |
| 271 // TODO(estade): remove IDR_THEME_TOOLBAR when MD is default. | 270 // TODO(estade): remove IDR_THEME_TOOLBAR when MD is default. |
| 272 if (theme_provider->HasCustomImage(IDR_THEME_TOOLBAR) || | 271 if (theme_provider->HasCustomImage(IDR_THEME_TOOLBAR) || |
| 273 !ui::MaterialDesignController::IsModeMaterial()) { | 272 !ui::MaterialDesignController::IsModeMaterial()) { |
| 274 canvas->TileImageInt(*theme_provider->GetImageSkiaNamed(IDR_THEME_TOOLBAR), | 273 canvas->TileImageInt(*theme_provider->GetImageSkiaNamed(IDR_THEME_TOOLBAR), |
| 275 background_origin.x(), | 274 background_origin.x(), |
| 276 background_origin.y(), | 275 background_origin.y(), |
| 277 bounds.x(), | 276 bounds.x(), |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 PaintAttachedBookmarkBar(canvas, bookmark_bar_view_, browser_view_, | 432 PaintAttachedBookmarkBar(canvas, bookmark_bar_view_, browser_view_, |
| 434 toolbar_overlap); | 433 toolbar_overlap); |
| 435 } | 434 } |
| 436 | 435 |
| 437 if (!bookmark_bar_view_->IsDetached() || detached_alpha == 0) | 436 if (!bookmark_bar_view_->IsDetached() || detached_alpha == 0) |
| 438 return; | 437 return; |
| 439 | 438 |
| 440 // While animating, set opacity to cross-fade between attached and detached | 439 // While animating, set opacity to cross-fade between attached and detached |
| 441 // backgrounds including their respective separators. | 440 // backgrounds including their respective separators. |
| 442 canvas->SaveLayerAlpha(detached_alpha); | 441 canvas->SaveLayerAlpha(detached_alpha); |
| 443 PaintDetachedBookmarkBar(canvas, bookmark_bar_view_, browser_->profile()); | 442 PaintDetachedBookmarkBar(canvas, bookmark_bar_view_); |
| 444 canvas->Restore(); | 443 canvas->Restore(); |
| 445 } | 444 } |
| 446 | 445 |
| 447 /////////////////////////////////////////////////////////////////////////////// | 446 /////////////////////////////////////////////////////////////////////////////// |
| 448 // BrowserView, public: | 447 // BrowserView, public: |
| 449 | 448 |
| 450 // static | 449 // static |
| 451 const char BrowserView::kViewClassName[] = "BrowserView"; | 450 const char BrowserView::kViewClassName[] = "BrowserView"; |
| 452 | 451 |
| 453 BrowserView::BrowserView() | 452 BrowserView::BrowserView() |
| (...skipping 2281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2735 } | 2734 } |
| 2736 | 2735 |
| 2737 extensions::ActiveTabPermissionGranter* | 2736 extensions::ActiveTabPermissionGranter* |
| 2738 BrowserView::GetActiveTabPermissionGranter() { | 2737 BrowserView::GetActiveTabPermissionGranter() { |
| 2739 content::WebContents* web_contents = GetActiveWebContents(); | 2738 content::WebContents* web_contents = GetActiveWebContents(); |
| 2740 if (!web_contents) | 2739 if (!web_contents) |
| 2741 return nullptr; | 2740 return nullptr; |
| 2742 return extensions::TabHelper::FromWebContents(web_contents) | 2741 return extensions::TabHelper::FromWebContents(web_contents) |
| 2743 ->active_tab_permission_granter(); | 2742 ->active_tab_permission_granter(); |
| 2744 } | 2743 } |
| OLD | NEW |