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

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

Issue 1685763004: Fix various issues with popup/app window layout/drawing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup
Patch Set: Fix unittest Created 4 years, 10 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 (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/glass_browser_frame_view.h" 5 #include "chrome/browser/ui/views/frame/glass_browser_frame_view.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/win/windows_version.h" 8 #include "base/win/windows_version.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/app/chrome_dll_resource.h" 10 #include "chrome/app/chrome_dll_resource.h"
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 nonclient_border_thickness, frame_top_border_height, 244 nonclient_border_thickness, frame_top_border_height,
245 kResizeCornerWidth - dwm_margin, frame()->widget_delegate()->CanResize()); 245 kResizeCornerWidth - dwm_margin, frame()->widget_delegate()->CanResize());
246 // Fall back to the caption if no other component matches. 246 // Fall back to the caption if no other component matches.
247 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; 247 return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
248 } 248 }
249 249
250 /////////////////////////////////////////////////////////////////////////////// 250 ///////////////////////////////////////////////////////////////////////////////
251 // GlassBrowserFrameView, views::View overrides: 251 // GlassBrowserFrameView, views::View overrides:
252 252
253 void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) { 253 void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) {
254 if (!browser_view()->IsTabStripVisible())
255 return;
254 if (IsToolbarVisible()) 256 if (IsToolbarVisible())
255 PaintToolbarBackground(canvas); 257 PaintToolbarBackground(canvas);
256 PaintClientEdge(canvas); 258 if (!frame()->IsMaximized())
259 PaintClientEdge(canvas);
257 } 260 }
258 261
259 void GlassBrowserFrameView::Layout() { 262 void GlassBrowserFrameView::Layout() {
260 if (browser_view()->IsRegularOrGuestSession()) 263 if (browser_view()->IsRegularOrGuestSession())
261 LayoutNewStyleAvatar(); 264 LayoutNewStyleAvatar();
262 LayoutIncognitoIcon(); 265 LayoutIncognitoIcon();
263 LayoutClientView(); 266 LayoutClientView();
264 } 267 }
265 268
266 /////////////////////////////////////////////////////////////////////////////// 269 ///////////////////////////////////////////////////////////////////////////////
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 !browser_view()->toolbar()->GetPreferredSize().IsEmpty(); 334 !browser_view()->toolbar()->GetPreferredSize().IsEmpty();
332 } 335 }
333 336
334 void GlassBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) const { 337 void GlassBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) const {
335 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); 338 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
336 if (toolbar_bounds.IsEmpty()) 339 if (toolbar_bounds.IsEmpty())
337 return; 340 return;
338 gfx::Point toolbar_origin(toolbar_bounds.origin()); 341 gfx::Point toolbar_origin(toolbar_bounds.origin());
339 ConvertPointToTarget(browser_view(), this, &toolbar_origin); 342 ConvertPointToTarget(browser_view(), this, &toolbar_origin);
340 toolbar_bounds.set_origin(toolbar_origin); 343 toolbar_bounds.set_origin(toolbar_origin);
344
345 const ui::ThemeProvider* tp = GetThemeProvider();
346 gfx::ImageSkia* bg = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR);
347 int x = toolbar_bounds.x();
348 const int y = toolbar_bounds.y();
349 const int bg_y = GetTopInset(false) + Tab::GetYInsetForActiveTabBackground();
350 int w = toolbar_bounds.width();
341 const int h = toolbar_bounds.height(); 351 const int h = toolbar_bounds.height();
342 const bool md = ui::MaterialDesignController::IsModeMaterial();
343 const ui::ThemeProvider* tp = GetThemeProvider();
344 const SkColor separator_color = 352 const SkColor separator_color =
345 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR); 353 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR);
354 if (ui::MaterialDesignController::IsModeMaterial()) {
355 // Background. The top stroke is drawn above the toolbar bounds, so unlike
356 // in the non-Material Design code below, we don't need to exclude any
357 // region from having the background image drawn over it.
358 if (tp->HasCustomImage(IDR_THEME_TOOLBAR)) {
359 canvas->TileImageInt(*bg, x + GetThemeBackgroundXInset(), y - bg_y, x, y,
360 w, h);
361 } else {
362 canvas->FillRect(toolbar_bounds,
363 tp->GetColor(ThemeProperties::COLOR_TOOLBAR));
364 }
346 365
347 if (browser_view()->IsTabStripVisible()) { 366 // Material Design has no corners to mask out.
348 gfx::ImageSkia* bg = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR);
349 int x = toolbar_bounds.x();
350 const int y = toolbar_bounds.y();
351 const int bg_y =
352 GetTopInset(false) + Tab::GetYInsetForActiveTabBackground();
353 int w = toolbar_bounds.width();
354 367
355 if (md) { 368 // Top stroke. For Material Design, the toolbar has no side strokes.
356 // Background. The top stroke is drawn above the toolbar bounds, so 369 gfx::Rect separator_rect(x, y, w, 0);
357 // unlike in the non-Material Design code below, we don't need to exclude 370 gfx::ScopedCanvas scoped_canvas(canvas);
358 // any region from having the background image drawn over it. 371 gfx::Rect tabstrip_bounds(GetBoundsForTabStrip(browser_view()->tabstrip()));
359 if (tp->HasCustomImage(IDR_THEME_TOOLBAR)) { 372 tabstrip_bounds.set_x(GetMirroredXForRect(tabstrip_bounds));
360 canvas->TileImageInt(*bg, x + GetThemeBackgroundXInset(), y - bg_y, x, 373 canvas->sk_canvas()->clipRect(gfx::RectToSkRect(tabstrip_bounds),
361 y, w, h); 374 SkRegion::kDifference_Op);
362 } else { 375 separator_rect.set_y(tabstrip_bounds.bottom());
363 canvas->FillRect(toolbar_bounds, 376 BrowserView::Paint1pxHorizontalLine(
364 tp->GetColor(ThemeProperties::COLOR_TOOLBAR)); 377 canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR),
365 } 378 separator_rect, true);
366 379
367 // Material Design has no corners to mask out. 380 // Toolbar/content separator.
381 toolbar_bounds.Inset(kClientEdgeThickness, 0);
382 BrowserView::Paint1pxHorizontalLine(canvas, separator_color, toolbar_bounds,
383 true);
384 } else {
385 // Background. The top stroke is drawn using the IDR_CONTENT_TOP_XXX
386 // images, which overlay the toolbar. The top 2 px of these images is the
387 // actual top stroke + shadow, and is partly transparent, so the toolbar
388 // background shouldn't be drawn over it.
389 const int bg_dest_y = y + kContentEdgeShadowThickness;
390 canvas->TileImageInt(*bg, x + GetThemeBackgroundXInset(), bg_dest_y - bg_y,
391 x, bg_dest_y, w, h - kContentEdgeShadowThickness);
368 392
369 // Top stroke. For Material Design, the toolbar has no side strokes. 393 // On Windows 10+ where we don't draw our own window border but rather go
370 gfx::Rect separator_rect(x, y, w, 0); 394 // right to the system border, the toolbar has no corners or side strokes.
371 gfx::ScopedCanvas scoped_canvas(canvas); 395 if (base::win::GetVersion() < base::win::VERSION_WIN10) {
372 gfx::Rect tabstrip_bounds( 396 // Mask out the corners.
373 GetBoundsForTabStrip(browser_view()->tabstrip())); 397 gfx::ImageSkia* left = tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER);
374 tabstrip_bounds.set_x(GetMirroredXForRect(tabstrip_bounds)); 398 const int img_w = left->width();
375 canvas->sk_canvas()->clipRect(gfx::RectToSkRect(tabstrip_bounds), 399 x -= kContentEdgeShadowThickness;
376 SkRegion::kDifference_Op); 400 SkPaint paint;
377 separator_rect.set_y(tabstrip_bounds.bottom()); 401 paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
378 BrowserView::Paint1pxHorizontalLine( 402 canvas->DrawImageInt(
379 canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR), 403 *tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER_MASK), 0, 0, img_w,
380 separator_rect, true); 404 h, x, y, img_w, h, false, paint);
381 } else { 405 const int right_x =
382 // Background. The top stroke is drawn using the IDR_CONTENT_TOP_XXX 406 toolbar_bounds.right() + kContentEdgeShadowThickness - img_w;
383 // images, which overlay the toolbar. The top 2 px of these images is the 407 canvas->DrawImageInt(
384 // actual top stroke + shadow, and is partly transparent, so the toolbar 408 *tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER_MASK), 0, 0,
385 // background shouldn't be drawn over it. 409 img_w, h, right_x, y, img_w, h, false, paint);
386 const int split_point = std::min(kContentEdgeShadowThickness, h);
387 if (h > split_point) {
388 const int split_y = y + split_point;
389 canvas->TileImageInt(*bg, x + GetThemeBackgroundXInset(),
390 split_y - bg_y, x, split_y, w, h - split_point);
391 }
392 410
393 // On Windows 10+ where we don't draw our own window border but rather go 411 // Corner and side strokes.
394 // right to the system border, the toolbar has no corners or side strokes. 412 canvas->DrawImageInt(*left, 0, 0, img_w, h, x, y, img_w, h, false);
395 if (base::win::GetVersion() < base::win::VERSION_WIN10) { 413 canvas->DrawImageInt(
396 // Mask out the corners. 414 *tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER), 0, 0, img_w, h,
397 gfx::ImageSkia* left = 415 right_x, y, img_w, h, false);
398 tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER);
399 const int img_w = left->width();
400 x -= kContentEdgeShadowThickness;
401 SkPaint paint;
402 paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
403 canvas->DrawImageInt(
404 *tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER_MASK), 0, 0,
405 img_w, h, x, y, img_w, h, false, paint);
406 const int right_x =
407 toolbar_bounds.right() + kContentEdgeShadowThickness - img_w;
408 canvas->DrawImageInt(
409 *tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER_MASK), 0, 0,
410 img_w, h, right_x, y, img_w, h, false, paint);
411 416
412 // Corner and side strokes. 417 x += img_w;
413 canvas->DrawImageInt(*left, 0, 0, img_w, h, x, y, img_w, h, false); 418 w = right_x - x;
414 canvas->DrawImageInt( 419 }
415 *tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER), 0, 0, img_w,
416 h, right_x, y, img_w, h, false);
417 420
418 x += img_w; 421 // Top stroke.
419 w = right_x - x; 422 canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER), x, y,
420 } 423 w, kContentEdgeShadowThickness);
421 424
422 // Top stroke. 425 // Toolbar/content separator.
423 canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER), x, y, 426 toolbar_bounds.Inset(kClientEdgeThickness, h - kClientEdgeThickness,
424 w, split_point); 427 kClientEdgeThickness, 0);
425 }
426 }
427
428 // Toolbar/content separator.
429 toolbar_bounds.Inset(kClientEdgeThickness, h - kClientEdgeThickness,
430 kClientEdgeThickness, 0);
431 if (md) {
432 BrowserView::Paint1pxHorizontalLine(canvas, separator_color,
433 toolbar_bounds, true);
434 } else {
435 canvas->FillRect(toolbar_bounds, separator_color); 428 canvas->FillRect(toolbar_bounds, separator_color);
436 } 429 }
437 } 430 }
438 431
439 void GlassBrowserFrameView::PaintClientEdge(gfx::Canvas* canvas) const { 432 void GlassBrowserFrameView::PaintClientEdge(gfx::Canvas* canvas) const {
440 gfx::Rect client_bounds = CalculateClientAreaBounds();
441 int y = client_bounds.y();
442 const bool normal_mode = browser_view()->IsTabStripVisible();
443 const ui::ThemeProvider* tp = GetThemeProvider();
444 const SkColor toolbar_color =
445 normal_mode
446 ? tp->GetColor(ThemeProperties::COLOR_TOOLBAR)
447 : ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_TOOLBAR,
448 browser_view()->IsOffTheRecord());
449
450 const gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
451 if (!normal_mode) {
452 // The toolbar isn't going to draw a top edge for us, so draw one ourselves.
453 client_bounds.Offset(0, toolbar_bounds.y());
454 client_bounds.Inset(-kClientEdgeThickness, 0, -kClientEdgeThickness,
455 client_bounds.height() - kClientEdgeThickness);
456 canvas->FillRect(client_bounds, toolbar_color);
457
458 // Popup and app windows don't custom-draw any other edges, so we're done.
459 return;
460 }
461
462 // In maximized mode, the only edge to draw is the top one, so we're done.
463 if (frame()->IsMaximized())
464 return;
465
466 const int x = client_bounds.x();
467 // Pre-Material Design, the client edge images start below the toolbar. In MD 433 // Pre-Material Design, the client edge images start below the toolbar. In MD
468 // the client edge images start at the top of the toolbar. 434 // the client edge images start at the top of the toolbar.
435 gfx::Rect client_bounds = CalculateClientAreaBounds();
436 const int x = client_bounds.x();
469 const bool md = ui::MaterialDesignController::IsModeMaterial(); 437 const bool md = ui::MaterialDesignController::IsModeMaterial();
470 y += md ? toolbar_bounds.y() : toolbar_bounds.bottom(); 438 const gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
439 const int y =
440 client_bounds.y() + (md ? toolbar_bounds.y() : toolbar_bounds.bottom());
471 const int w = client_bounds.width(); 441 const int w = client_bounds.width();
472 const int right = client_bounds.right(); 442 const int right = client_bounds.right();
473 const int bottom = std::max(y, height() - NonClientBorderThickness(false)); 443 const int bottom = std::max(y, height() - NonClientBorderThickness(false));
474 const int height = bottom - y; 444 const int height = bottom - y;
475 445
476 // Draw the client edge images. For non-MD, we fill the toolbar color 446 // Draw the client edge images. For non-MD, we fill the toolbar color
477 // underneath these images so they will lighten/darken it appropriately to 447 // underneath these images so they will lighten/darken it appropriately to
478 // create a "3D shaded" effect. For MD, where we want a flatter appearance, 448 // create a "3D shaded" effect. For MD, where we want a flatter appearance,
479 // we do the filling afterwards so the user sees the unmodified toolbar color. 449 // we do the filling afterwards so the user sees the unmodified toolbar color.
450 const ui::ThemeProvider* tp = GetThemeProvider();
451 const SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR);
480 if (!md) 452 if (!md)
481 FillClientEdgeRects(x, y, right, bottom, toolbar_color, canvas); 453 FillClientEdgeRects(x, y, right, bottom, toolbar_color, canvas);
482 gfx::ImageSkia* right_image = tp->GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE); 454 gfx::ImageSkia* right_image = tp->GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE);
483 const int img_w = right_image->width(); 455 const int img_w = right_image->width();
484 canvas->TileImageInt(*right_image, right, y, img_w, height); 456 canvas->TileImageInt(*right_image, right, y, img_w, height);
485 canvas->DrawImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER), 457 canvas->DrawImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER),
486 right, bottom); 458 right, bottom);
487 gfx::ImageSkia* bottom_image = 459 gfx::ImageSkia* bottom_image =
488 tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER); 460 tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER);
489 canvas->TileImageInt(*bottom_image, x, bottom, w, bottom_image->height()); 461 canvas->TileImageInt(*bottom_image, x, bottom, w, bottom_image->height());
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 static bool initialized = false; 651 static bool initialized = false;
680 if (!initialized) { 652 if (!initialized) {
681 for (int i = 0; i < kThrobberIconCount; ++i) { 653 for (int i = 0; i < kThrobberIconCount; ++i) {
682 throbber_icons_[i] = 654 throbber_icons_[i] =
683 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); 655 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i);
684 DCHECK(throbber_icons_[i]); 656 DCHECK(throbber_icons_[i]);
685 } 657 }
686 initialized = true; 658 initialized = true;
687 } 659 }
688 } 660 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698