Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: chrome/browser/ui/views/frame/browser_view.cc

Issue 2441863002: Remove some more !IsModeMaterial code. (Closed)
Patch Set: pull more shades Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 194
195 // The name of a key to store on the window handle so that other code can 195 // The name of a key to store on the window handle so that other code can
196 // locate this object using just the handle. 196 // locate this object using just the handle.
197 const char* const kBrowserViewKey = "__BROWSER_VIEW__"; 197 const char* const kBrowserViewKey = "__BROWSER_VIEW__";
198 198
199 // The number of milliseconds between loading animation frames. 199 // The number of milliseconds between loading animation frames.
200 const int kLoadingAnimationFrameTimeMs = 30; 200 const int kLoadingAnimationFrameTimeMs = 30;
201 201
202 // Paints the horizontal border separating the Bookmarks Bar from the Toolbar 202 // Paints the horizontal border separating the Bookmarks Bar from the Toolbar
203 // or page content according to |at_top| with |color|. 203 // or page content according to |at_top| with |color|.
204 void PaintHorizontalBorder(gfx::Canvas* canvas,
205 BookmarkBarView* view,
206 bool at_top,
207 SkColor color) {
208 int thickness = views::NonClientFrameView::kClientEdgeThickness;
209 int y = at_top ? 0 : (view->height() - thickness);
210 canvas->FillRect(gfx::Rect(0, y, view->width(), thickness), color);
211 }
212
213 void PaintDetachedBookmarkBar(gfx::Canvas* canvas, 204 void PaintDetachedBookmarkBar(gfx::Canvas* canvas,
214 BookmarkBarView* view) { 205 BookmarkBarView* view) {
215 // Paint background for detached state; if animating, this is fade in/out. 206 // Paint background for detached state; if animating, this is fade in/out.
216 const ui::ThemeProvider* tp = view->GetThemeProvider(); 207 const ui::ThemeProvider* tp = view->GetThemeProvider();
217 gfx::Rect fill_rect = view->GetLocalBounds(); 208 gfx::Rect fill_rect = view->GetLocalBounds();
218 // In MD, we have to not color the top 1dp, because that should be painted by 209 // We have to not color the top 1dp, because that should be painted by the
219 // the toolbar. We will, however, paint the 1px separator at the bottom of the 210 // toolbar. We will, however, paint the 1px separator at the bottom of the
220 // first dp. See crbug.com/610359 211 // first dp. See crbug.com/610359
221 if (ui::MaterialDesignController::IsModeMaterial()) 212 fill_rect.Inset(0, 1, 0, 0);
222 fill_rect.Inset(0, 1, 0, 0);
223 213
224 // In detached mode, the bar is meant to overlap with |contents_container_|. 214 // In detached mode, the bar is meant to overlap with |contents_container_|.
225 // The detached background color may be partially transparent, but the layer 215 // The detached background color may be partially transparent, but the layer
226 // for |view| must be painted opaquely to avoid subpixel anti-aliasing 216 // for |view| must be painted opaquely to avoid subpixel anti-aliasing
227 // artifacts, so we recreate the contents container base color here. 217 // artifacts, so we recreate the contents container base color here.
228 canvas->FillRect(fill_rect, 218 canvas->FillRect(fill_rect,
229 tp->GetColor(ThemeProperties::COLOR_CONTROL_BACKGROUND)); 219 tp->GetColor(ThemeProperties::COLOR_CONTROL_BACKGROUND));
230 canvas->FillRect( 220 canvas->FillRect(
231 fill_rect, 221 fill_rect,
232 tp->GetColor(ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_BACKGROUND)); 222 tp->GetColor(ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_BACKGROUND));
233 223
234 // Draw the separators above and below bookmark bar; 224 // Draw the separators above and below bookmark bar;
235 // if animating, these are fading in/out. 225 // if animating, these are fading in/out.
236 SkColor separator_color = 226 SkColor separator_color =
237 tp->GetColor(ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_SEPARATOR); 227 tp->GetColor(ThemeProperties::COLOR_DETACHED_BOOKMARK_BAR_SEPARATOR);
238 228
239 // In material mode the toolbar bottom stroke serves as our top stroke.
240 if (!ui::MaterialDesignController::IsModeMaterial())
241 PaintHorizontalBorder(canvas, view, true, separator_color);
242
243 // For the bottom separator, increase the luminance. Either double it or halve 229 // For the bottom separator, increase the luminance. Either double it or halve
244 // the distance to 1.0, whichever is less of a difference. 230 // the distance to 1.0, whichever is less of a difference.
245 color_utils::HSL hsl; 231 color_utils::HSL hsl;
246 color_utils::SkColorToHSL(separator_color, &hsl); 232 color_utils::SkColorToHSL(separator_color, &hsl);
247 hsl.l = std::min((hsl.l + 1) / 2, hsl.l * 2); 233 hsl.l = std::min((hsl.l + 1) / 2, hsl.l * 2);
248 BrowserView::Paint1pxHorizontalLine( 234 BrowserView::Paint1pxHorizontalLine(
249 canvas, color_utils::HSLToSkColor(hsl, SK_AlphaOPAQUE), 235 canvas, color_utils::HSLToSkColor(hsl, SK_AlphaOPAQUE),
250 view->GetLocalBounds(), true); 236 view->GetLocalBounds(), true);
251 } 237 }
252 238
253 // Paints the background (including the theme image behind content area) for 239 // Paints the background (including the theme image behind content area) for
254 // the Bookmarks Bar when it is attached to the Toolbar into |bounds|. 240 // the Bookmarks Bar when it is attached to the Toolbar into |bounds|.
255 // |background_origin| is the origin to use for painting the theme image. 241 // |background_origin| is the origin to use for painting the theme image.
256 void PaintBackgroundAttachedMode(gfx::Canvas* canvas, 242 void PaintBackgroundAttachedMode(gfx::Canvas* canvas,
257 const ui::ThemeProvider* theme_provider, 243 const ui::ThemeProvider* theme_provider,
258 const gfx::Rect& bounds, 244 const gfx::Rect& bounds,
259 const gfx::Point& background_origin) { 245 const gfx::Point& background_origin) {
260 canvas->DrawColor(theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR)); 246 canvas->DrawColor(theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR));
261 247
262 // Always tile the background image in pre-MD. In MD, only tile if there's a 248 // Always tile the background image in pre-MD. In MD, only tile if there's a
263 // non-default image. 249 // non-default image.
Peter Kasting 2016/10/21 21:07:50 Nit: Update comment
Evan Stade 2016/10/21 22:11:12 Done.
264 // TODO(estade): remove IDR_THEME_TOOLBAR when MD is default. 250 if (theme_provider->HasCustomImage(IDR_THEME_TOOLBAR)) {
Peter Kasting 2016/10/21 21:07:50 Not sure what this meant
Evan Stade 2016/10/21 22:11:12 it meant the asset could be removed (i.e. what thi
265 if (theme_provider->HasCustomImage(IDR_THEME_TOOLBAR) ||
266 !ui::MaterialDesignController::IsModeMaterial()) {
267 canvas->TileImageInt(*theme_provider->GetImageSkiaNamed(IDR_THEME_TOOLBAR), 251 canvas->TileImageInt(*theme_provider->GetImageSkiaNamed(IDR_THEME_TOOLBAR),
268 background_origin.x(), 252 background_origin.x(),
269 background_origin.y(), 253 background_origin.y(),
270 bounds.x(), 254 bounds.x(),
271 bounds.y(), 255 bounds.y(),
272 bounds.width(), 256 bounds.width(),
273 bounds.height()); 257 bounds.height());
274 } 258 }
275
276 #if defined(USE_ASH)
277 if (!ui::MaterialDesignController::IsModeMaterial()) {
278 // The pre-material design version of Ash provides additional lightening
279 // at the edges of the toolbar.
280 gfx::ImageSkia* toolbar_left =
281 theme_provider->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_LEFT);
282 canvas->TileImageInt(*toolbar_left,
283 bounds.x(),
284 bounds.y(),
285 toolbar_left->width(),
286 bounds.height());
287 gfx::ImageSkia* toolbar_right =
288 theme_provider->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT);
289 canvas->TileImageInt(*toolbar_right,
290 bounds.right() - toolbar_right->width(),
291 bounds.y(),
292 toolbar_right->width(),
293 bounds.height());
294 }
295 #endif // USE_ASH
296 } 259 }
297 260
298 void PaintAttachedBookmarkBar(gfx::Canvas* canvas, 261 void PaintAttachedBookmarkBar(gfx::Canvas* canvas,
299 BookmarkBarView* view, 262 BookmarkBarView* view,
300 BrowserView* browser_view, 263 BrowserView* browser_view,
301 int toolbar_overlap) { 264 int toolbar_overlap) {
302 // Paint background for attached state, this is fade in/out. 265 // Paint background for attached state.
303 gfx::Point background_image_offset = 266 gfx::Point background_image_offset =
304 browser_view->OffsetPointForToolbarBackgroundImage( 267 browser_view->OffsetPointForToolbarBackgroundImage(
305 gfx::Point(view->GetMirroredX(), view->y())); 268 gfx::Point(view->GetMirroredX(), view->y()));
306 PaintBackgroundAttachedMode(canvas, view->GetThemeProvider(), 269 PaintBackgroundAttachedMode(canvas, view->GetThemeProvider(),
307 view->GetLocalBounds(), background_image_offset); 270 view->GetLocalBounds(), background_image_offset);
308 if (view->height() >= toolbar_overlap) { 271 if (view->height() >= toolbar_overlap) {
309 // Draw the separator below the Bookmarks Bar; this is fading in/out. 272 BrowserView::Paint1pxHorizontalLine(
310 if (ui::MaterialDesignController::IsModeMaterial()) { 273 canvas, view->GetThemeProvider()->GetColor(
311 BrowserView::Paint1pxHorizontalLine( 274 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR),
312 canvas, view->GetThemeProvider()->GetColor( 275 view->GetLocalBounds(), true);
313 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR),
314 view->GetLocalBounds(), true);
315 } else {
316 PaintHorizontalBorder(
317 canvas, view, false,
318 view->GetThemeProvider()->GetColor(
319 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR));
320 }
321 } 276 }
322 } 277 }
323 278
324 } // namespace 279 } // namespace
325 280
326 /////////////////////////////////////////////////////////////////////////////// 281 ///////////////////////////////////////////////////////////////////////////////
327 // Delegate implementation for BrowserViewLayout. Usually just forwards calls 282 // Delegate implementation for BrowserViewLayout. Usually just forwards calls
328 // into BrowserView. 283 // into BrowserView.
329 class BrowserViewLayoutDelegateImpl : public BrowserViewLayoutDelegate { 284 class BrowserViewLayoutDelegateImpl : public BrowserViewLayoutDelegate {
330 public: 285 public:
(...skipping 1609 matching lines...) Expand 10 before | Expand all | Expand 10 after
1940 1895
1941 void BrowserView::ChildPreferredSizeChanged(View* child) { 1896 void BrowserView::ChildPreferredSizeChanged(View* child) {
1942 Layout(); 1897 Layout();
1943 } 1898 }
1944 1899
1945 void BrowserView::GetAccessibleState(ui::AXViewState* state) { 1900 void BrowserView::GetAccessibleState(ui::AXViewState* state) {
1946 state->role = ui::AX_ROLE_CLIENT; 1901 state->role = ui::AX_ROLE_CLIENT;
1947 } 1902 }
1948 1903
1949 void BrowserView::OnThemeChanged() { 1904 void BrowserView::OnThemeChanged() {
1950 if (!IsRegularOrGuestSession() && 1905 if (!IsRegularOrGuestSession()) {
1951 ui::MaterialDesignController::IsModeMaterial()) {
1952 // When the theme changes, the native theme may also change (in incognito, 1906 // When the theme changes, the native theme may also change (in incognito,
1953 // the usage of dark or normal hinges on the browser theme), so we have to 1907 // the usage of dark or normal hinges on the browser theme), so we have to
1954 // propagate both kinds of change. 1908 // propagate both kinds of change.
1955 base::AutoReset<bool> reset(&handling_theme_changed_, true); 1909 base::AutoReset<bool> reset(&handling_theme_changed_, true);
1956 #if defined(OS_WIN) 1910 #if defined(OS_WIN)
1957 ui::NativeThemeDarkWin::instance()->NotifyObservers(); 1911 ui::NativeThemeDarkWin::instance()->NotifyObservers();
1958 ui::NativeThemeWin::instance()->NotifyObservers(); 1912 ui::NativeThemeWin::instance()->NotifyObservers();
1959 #elif defined(OS_LINUX) 1913 #elif defined(OS_LINUX)
1960 ui::NativeThemeDarkAura::instance()->NotifyObservers(); 1914 ui::NativeThemeDarkAura::instance()->NotifyObservers();
1961 ui::NativeThemeAura::instance()->NotifyObservers(); 1915 ui::NativeThemeAura::instance()->NotifyObservers();
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
2636 } 2590 }
2637 2591
2638 extensions::ActiveTabPermissionGranter* 2592 extensions::ActiveTabPermissionGranter*
2639 BrowserView::GetActiveTabPermissionGranter() { 2593 BrowserView::GetActiveTabPermissionGranter() {
2640 content::WebContents* web_contents = GetActiveWebContents(); 2594 content::WebContents* web_contents = GetActiveWebContents();
2641 if (!web_contents) 2595 if (!web_contents)
2642 return nullptr; 2596 return nullptr;
2643 return extensions::TabHelper::FromWebContents(web_contents) 2597 return extensions::TabHelper::FromWebContents(web_contents)
2644 ->active_tab_permission_granter(); 2598 ->active_tab_permission_granter();
2645 } 2599 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698