Chromium Code Reviews| 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 int thickness = views::NonClientFrameView::kClientEdgeThickness; | 216 int thickness = views::NonClientFrameView::kClientEdgeThickness; |
| 217 int y = at_top ? 0 : (view->height() - thickness); | 217 int y = at_top ? 0 : (view->height() - thickness); |
| 218 canvas->FillRect(gfx::Rect(0, y, view->width(), thickness), color); | 218 canvas->FillRect(gfx::Rect(0, y, view->width(), thickness), color); |
| 219 } | 219 } |
| 220 | 220 |
| 221 // TODO(kuan): These functions are temporarily for the bookmark bar while its | 221 // TODO(kuan): These functions are temporarily for the bookmark bar while its |
| 222 // detached state is at the top of the page; it'll be moved to float on the | 222 // detached state is at the top of the page; it'll be moved to float on the |
| 223 // content page in the very near future, at which time, these local functions | 223 // content page in the very near future, at which time, these local functions |
| 224 // will be removed. | 224 // will be removed. |
| 225 void PaintDetachedBookmarkBar(gfx::Canvas* canvas, | 225 void PaintDetachedBookmarkBar(gfx::Canvas* canvas, |
| 226 BookmarkBarView* view, | 226 BookmarkBarView* view) { |
| 227 Profile* profile) { | |
| 228 // Paint background for detached state; if animating, this is fade in/out. | 227 // Paint background for detached state; if animating, this is fade in/out. |
| 229 const ui::ThemeProvider& tp = | 228 const ui::ThemeProvider* tp = view->GetThemeProvider(); |
| 230 ThemeService::GetThemeProviderForProfile(profile); | |
| 231 canvas->DrawColor( | 229 canvas->DrawColor( |
| 232 tp.GetColor(ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_BACKGROUND)); | 230 tp->GetColor(ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_BACKGROUND)); |
| 231 | |
| 233 // Draw the separators above and below bookmark bar; | 232 // Draw the separators above and below bookmark bar; |
| 234 // if animating, these are fading in/out. | 233 // if animating, these are fading in/out. |
| 235 SkColor separator_color = | 234 SkColor separator_color = |
| 236 tp.GetColor(ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_SEPARATOR); | 235 tp->GetColor(ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_SEPARATOR); |
| 237 | 236 |
| 238 if (ui::MaterialDesignController::IsModeMaterial()) { | 237 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 239 BrowserView::Paint1pxHorizontalLine( | 238 BrowserView::Paint1pxHorizontalLine( |
| 240 canvas, separator_color, | 239 canvas, separator_color, |
| 241 gfx::Rect(0, 0, view->width(), | 240 gfx::Rect(0, 0, view->width(), |
| 242 views::NonClientFrameView::kClientEdgeThickness), | 241 views::NonClientFrameView::kClientEdgeThickness), |
| 243 true); | 242 true); |
| 244 } else { | 243 } else { |
| 245 PaintHorizontalBorder(canvas, view, true, separator_color); | 244 PaintHorizontalBorder(canvas, view, true, separator_color); |
| 246 } | 245 } |
| 247 | 246 |
| 248 // For the bottom separator, increase the luminance. Either double it or halve | 247 // For the bottom separator, increase the luminance. Either double it or halve |
| 249 // the distance to 1.0, whichever is less of a difference. | 248 // the distance to 1.0, whichever is less of a difference. |
| 250 color_utils::HSL hsl; | 249 color_utils::HSL hsl; |
| 251 color_utils::SkColorToHSL(separator_color, &hsl); | 250 color_utils::SkColorToHSL(separator_color, &hsl); |
| 252 hsl.l = std::min((hsl.l + 1) / 2, hsl.l * 2); | 251 hsl.l = std::min((hsl.l + 1) / 2, hsl.l * 2); |
| 253 BrowserView::Paint1pxHorizontalLine( | 252 BrowserView::Paint1pxHorizontalLine( |
| 254 canvas, color_utils::HSLToSkColor(hsl, SK_AlphaOPAQUE), | 253 canvas, color_utils::HSLToSkColor(hsl, SK_AlphaOPAQUE), |
| 255 view->GetLocalBounds(), true); | 254 view->GetLocalBounds(), true); |
| 256 } | 255 } |
| 257 | 256 |
| 258 // Paints the background (including the theme image behind content area) for | 257 // Paints the background (including the theme image behind content area) for |
| 259 // the Bookmarks Bar when it is attached to the Toolbar into |bounds|. | 258 // the Bookmarks Bar when it is attached to the Toolbar into |bounds|. |
| 260 // |background_origin| is the origin to use for painting the theme image. | 259 // |background_origin| is the origin to use for painting the theme image. |
| 261 void PaintBackgroundAttachedMode(gfx::Canvas* canvas, | 260 void PaintBackgroundAttachedMode(gfx::Canvas* canvas, |
| 262 const ui::ThemeProvider* theme_provider, | 261 const ui::ThemeProvider* theme_provider, |
| 263 const gfx::Rect& bounds, | 262 const gfx::Rect& bounds, |
| 264 const gfx::Point& background_origin) { | 263 const gfx::Point& background_origin) { |
| 265 canvas->FillRect(bounds, | 264 canvas->DrawColor(theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR)); |
| 266 theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR)); | |
| 267 | 265 |
| 268 // Always tile the background image in pre-MD. In MD, only tile if there's a | 266 // Always tile the background image in pre-MD. In MD, only tile if there's a |
| 269 // non-default image. | 267 // non-default image. |
| 270 // TODO(estade): remove IDR_THEME_TOOLBAR when MD is default. | 268 // TODO(estade): remove IDR_THEME_TOOLBAR when MD is default. |
| 271 if (theme_provider->HasCustomImage(IDR_THEME_TOOLBAR) || | 269 if (theme_provider->HasCustomImage(IDR_THEME_TOOLBAR) || |
| 272 !ui::MaterialDesignController::IsModeMaterial()) { | 270 !ui::MaterialDesignController::IsModeMaterial()) { |
| 273 canvas->TileImageInt(*theme_provider->GetImageSkiaNamed(IDR_THEME_TOOLBAR), | 271 canvas->TileImageInt(*theme_provider->GetImageSkiaNamed(IDR_THEME_TOOLBAR), |
| 274 background_origin.x(), | 272 background_origin.x(), |
| 275 background_origin.y(), | 273 background_origin.y(), |
| 276 bounds.x(), | 274 bounds.x(), |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 BrowserView* browser_view, | 415 BrowserView* browser_view, |
| 418 BookmarkBarView* bookmark_bar_view, | 416 BookmarkBarView* bookmark_bar_view, |
| 419 Browser* browser) | 417 Browser* browser) |
| 420 : browser_view_(browser_view), | 418 : browser_view_(browser_view), |
| 421 bookmark_bar_view_(bookmark_bar_view), | 419 bookmark_bar_view_(bookmark_bar_view), |
| 422 browser_(browser) { | 420 browser_(browser) { |
| 423 } | 421 } |
| 424 | 422 |
| 425 void BookmarkBarViewBackground::Paint(gfx::Canvas* canvas, | 423 void BookmarkBarViewBackground::Paint(gfx::Canvas* canvas, |
| 426 views::View* view) const { | 424 views::View* view) const { |
| 425 // Start with a blank canvas --- the attached and detached colors may not be | |
| 426 // fully opaque. | |
| 427 canvas->DrawColor(SK_ColorWHITE); | |
|
sky
2016/04/05 19:14:01
Why is white the right color here?
Evan Stade
2016/04/05 19:36:10
That is a good question. Initially I used black, b
Evan Stade
2016/04/05 20:31:51
I looked into it and I think that previously the f
| |
| 428 | |
| 427 int toolbar_overlap = bookmark_bar_view_->GetToolbarOverlap(); | 429 int toolbar_overlap = bookmark_bar_view_->GetToolbarOverlap(); |
| 428 | 430 |
| 429 SkAlpha detached_alpha = static_cast<SkAlpha>( | 431 SkAlpha detached_alpha = static_cast<SkAlpha>( |
| 430 bookmark_bar_view_->size_animation().CurrentValueBetween(0xff, 0)); | 432 bookmark_bar_view_->size_animation().CurrentValueBetween(0xff, 0)); |
| 431 if (detached_alpha != 0xff) { | 433 if (detached_alpha != 0xff) { |
| 432 PaintAttachedBookmarkBar(canvas, bookmark_bar_view_, browser_view_, | 434 PaintAttachedBookmarkBar(canvas, bookmark_bar_view_, browser_view_, |
| 433 toolbar_overlap); | 435 toolbar_overlap); |
| 434 } | 436 } |
| 435 | 437 |
| 436 if (!bookmark_bar_view_->IsDetached() || detached_alpha == 0) | 438 if (!bookmark_bar_view_->IsDetached() || detached_alpha == 0) |
| 437 return; | 439 return; |
| 438 | 440 |
| 439 // While animating, set opacity to cross-fade between attached and detached | 441 // While animating, set opacity to cross-fade between attached and detached |
| 440 // backgrounds including their respective separators. | 442 // backgrounds including their respective separators. |
| 441 canvas->SaveLayerAlpha(detached_alpha); | 443 canvas->SaveLayerAlpha(detached_alpha); |
| 442 PaintDetachedBookmarkBar(canvas, bookmark_bar_view_, browser_->profile()); | 444 PaintDetachedBookmarkBar(canvas, bookmark_bar_view_); |
| 443 canvas->Restore(); | 445 canvas->Restore(); |
| 444 } | 446 } |
| 445 | 447 |
| 446 /////////////////////////////////////////////////////////////////////////////// | 448 /////////////////////////////////////////////////////////////////////////////// |
| 447 // BrowserView, public: | 449 // BrowserView, public: |
| 448 | 450 |
| 449 // static | 451 // static |
| 450 const char BrowserView::kViewClassName[] = "BrowserView"; | 452 const char BrowserView::kViewClassName[] = "BrowserView"; |
| 451 | 453 |
| 452 BrowserView::BrowserView() | 454 BrowserView::BrowserView() |
| (...skipping 2214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2667 } | 2669 } |
| 2668 | 2670 |
| 2669 extensions::ActiveTabPermissionGranter* | 2671 extensions::ActiveTabPermissionGranter* |
| 2670 BrowserView::GetActiveTabPermissionGranter() { | 2672 BrowserView::GetActiveTabPermissionGranter() { |
| 2671 content::WebContents* web_contents = GetActiveWebContents(); | 2673 content::WebContents* web_contents = GetActiveWebContents(); |
| 2672 if (!web_contents) | 2674 if (!web_contents) |
| 2673 return nullptr; | 2675 return nullptr; |
| 2674 return extensions::TabHelper::FromWebContents(web_contents) | 2676 return extensions::TabHelper::FromWebContents(web_contents) |
| 2675 ->active_tab_permission_granter(); | 2677 ->active_tab_permission_granter(); |
| 2676 } | 2678 } |
| OLD | NEW |