| 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/glass_browser_frame_view.h" | 5 #include "chrome/browser/ui/views/frame/glass_browser_frame_view.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 nonclient_border_thickness, frame_top_border_height, | 241 nonclient_border_thickness, frame_top_border_height, |
| 242 kResizeCornerWidth - dwm_margin, frame()->widget_delegate()->CanResize()); | 242 kResizeCornerWidth - dwm_margin, frame()->widget_delegate()->CanResize()); |
| 243 // Fall back to the caption if no other component matches. | 243 // Fall back to the caption if no other component matches. |
| 244 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; | 244 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; |
| 245 } | 245 } |
| 246 | 246 |
| 247 /////////////////////////////////////////////////////////////////////////////// | 247 /////////////////////////////////////////////////////////////////////////////// |
| 248 // GlassBrowserFrameView, views::View overrides: | 248 // GlassBrowserFrameView, views::View overrides: |
| 249 | 249 |
| 250 void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) { | 250 void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) { |
| 251 if (browser_view()->IsToolbarVisible() && | 251 if (IsToolbarVisible()) |
| 252 browser_view()->toolbar()->ShouldPaintBackground()) | |
| 253 PaintToolbarBackground(canvas); | 252 PaintToolbarBackground(canvas); |
| 254 if (!frame()->IsMaximized()) | 253 PaintClientEdge(canvas); |
| 255 PaintRestoredClientEdge(canvas); | |
| 256 } | 254 } |
| 257 | 255 |
| 258 void GlassBrowserFrameView::Layout() { | 256 void GlassBrowserFrameView::Layout() { |
| 259 if (browser_view()->IsRegularOrGuestSession()) | 257 if (browser_view()->IsRegularOrGuestSession()) |
| 260 LayoutNewStyleAvatar(); | 258 LayoutNewStyleAvatar(); |
| 261 LayoutIncognitoIcon(); | 259 LayoutIncognitoIcon(); |
| 262 LayoutClientView(); | 260 LayoutClientView(); |
| 263 } | 261 } |
| 264 | 262 |
| 265 /////////////////////////////////////////////////////////////////////////////// | 263 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 // Annoyingly, the pre-MD layout uses different heights for the hit-test | 333 // Annoyingly, the pre-MD layout uses different heights for the hit-test |
| 336 // exclusion region (which we want here, since we're trying to size the border | 334 // exclusion region (which we want here, since we're trying to size the border |
| 337 // so that the region above the tab's hit-test zone matches) versus the shadow | 335 // so that the region above the tab's hit-test zone matches) versus the shadow |
| 338 // thickness. | 336 // thickness. |
| 339 const int exclusion = GetLayoutConstant(TAB_TOP_EXCLUSION_HEIGHT); | 337 const int exclusion = GetLayoutConstant(TAB_TOP_EXCLUSION_HEIGHT); |
| 340 return (frame()->IsMaximized() && !restored) ? | 338 return (frame()->IsMaximized() && !restored) ? |
| 341 (top - GetLayoutInsets(TAB).top() + 1) : | 339 (top - GetLayoutInsets(TAB).top() + 1) : |
| 342 (top + kNonClientRestoredExtraThickness - exclusion); | 340 (top + kNonClientRestoredExtraThickness - exclusion); |
| 343 } | 341 } |
| 344 | 342 |
| 343 bool GlassBrowserFrameView::IsToolbarVisible() const { |
| 344 return browser_view()->IsToolbarVisible() && |
| 345 !browser_view()->toolbar()->GetPreferredSize().IsEmpty(); |
| 346 } |
| 347 |
| 345 void GlassBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) { | 348 void GlassBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) { |
| 346 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); | 349 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); |
| 347 if (toolbar_bounds.IsEmpty()) | 350 if (toolbar_bounds.IsEmpty()) |
| 348 return; | 351 return; |
| 349 gfx::Point toolbar_origin(toolbar_bounds.origin()); | 352 gfx::Point toolbar_origin(toolbar_bounds.origin()); |
| 350 ConvertPointToTarget(browser_view(), this, &toolbar_origin); | 353 ConvertPointToTarget(browser_view(), this, &toolbar_origin); |
| 351 toolbar_bounds.set_origin(toolbar_origin); | 354 toolbar_bounds.set_origin(toolbar_origin); |
| 352 const int h = toolbar_bounds.height(); | 355 const int h = toolbar_bounds.height(); |
| 353 ui::ThemeProvider* tp = GetThemeProvider(); | 356 ui::ThemeProvider* tp = GetThemeProvider(); |
| 357 const SkColor separator_color = |
| 358 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_SEPARATOR); |
| 354 | 359 |
| 355 // Background. | 360 // Background. |
| 356 int x = toolbar_bounds.x(); | 361 if (browser_view()->IsTabStripVisible()) { |
| 357 const int y = toolbar_bounds.y(); | 362 int x = toolbar_bounds.x(); |
| 358 int w = toolbar_bounds.width(); | 363 const int y = toolbar_bounds.y(); |
| 364 int w = toolbar_bounds.width(); |
| 359 | 365 |
| 360 // The top stroke is drawn using the IDR_CONTENT_TOP_XXX images, which overlay | 366 // The top stroke is drawn using the IDR_CONTENT_TOP_XXX images, which |
| 361 // the toolbar. The top 2 px of these images is the actual top stroke + | 367 // overlay the toolbar. The top 2 px of these images is the actual top |
| 362 // shadow, and is partly transparent, so the toolbar background shouldn't be | 368 // stroke + shadow, and is partly transparent, so the toolbar background |
| 363 // drawn over it. | 369 // shouldn't be drawn over it. |
| 364 const int split_point = std::min(kContentEdgeShadowThickness, h); | 370 const int split_point = std::min(kContentEdgeShadowThickness, h); |
| 365 if (h > split_point) { | 371 if (h > split_point) { |
| 366 // Tile the toolbar image starting at the frame edge on the left and where | 372 // Tile the toolbar image starting at the frame edge on the left and where |
| 367 // the tabstrip is on the top. | 373 // the tabstrip is on the top. |
| 368 const int split_y = | 374 const int split_y = y + split_point; |
| 369 y + (browser_view()->IsTabStripVisible() ? split_point : 0); | 375 const int bg_y = |
| 370 const int bg_y = | 376 GetTopInset(false) + Tab::GetYInsetForActiveTabBackground(); |
| 371 GetTopInset(false) + Tab::GetYInsetForActiveTabBackground(); | 377 canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR), |
| 372 canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR), | 378 x + GetThemeBackgroundXInset(), split_y - bg_y, x, |
| 373 x + GetThemeBackgroundXInset(), split_y - bg_y, x, | 379 split_y, w, h - split_point); |
| 374 split_y, w, h - split_point); | 380 } |
| 375 } | |
| 376 | 381 |
| 377 if (browser_view()->IsTabStripVisible()) { | |
| 378 // On Windows 10+ where we don't draw our own window border but rather go | 382 // On Windows 10+ where we don't draw our own window border but rather go |
| 379 // right to the system border, the toolbar has no corners or side strokes. | 383 // right to the system border, the toolbar has no corners or side strokes. |
| 380 if (base::win::GetVersion() < base::win::VERSION_WIN10) { | 384 if (base::win::GetVersion() < base::win::VERSION_WIN10) { |
| 381 // Mask out the corners. | 385 // Mask out the corners. |
| 382 gfx::ImageSkia* left = tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER); | 386 gfx::ImageSkia* left = tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER); |
| 383 const int img_w = left->width(); | 387 const int img_w = left->width(); |
| 384 x -= kContentEdgeShadowThickness; | 388 x -= kContentEdgeShadowThickness; |
| 385 SkPaint paint; | 389 SkPaint paint; |
| 386 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); | 390 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); |
| 387 canvas->DrawImageInt( | 391 canvas->DrawImageInt( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 398 canvas->DrawImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER), | 402 canvas->DrawImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER), |
| 399 0, 0, img_w, h, right_x, y, img_w, h, false); | 403 0, 0, img_w, h, right_x, y, img_w, h, false); |
| 400 | 404 |
| 401 x += img_w; | 405 x += img_w; |
| 402 w = right_x - x; | 406 w = right_x - x; |
| 403 } | 407 } |
| 404 | 408 |
| 405 // Top stroke. | 409 // Top stroke. |
| 406 canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER), x, y, | 410 canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER), x, y, |
| 407 w, split_point); | 411 w, split_point); |
| 412 |
| 413 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 414 // Toolbar/content separator. |
| 415 toolbar_bounds.Inset(kClientEdgeThickness, 0); |
| 416 BrowserView::Paint1pxHorizontalLine(canvas, separator_color, |
| 417 toolbar_bounds); |
| 418 return; |
| 419 } |
| 408 } | 420 } |
| 409 | 421 |
| 410 // Toolbar/content separator. | 422 // Toolbar/content separator. |
| 411 const SkColor separator_color = | 423 toolbar_bounds.Inset(kClientEdgeThickness, h - kClientEdgeThickness, |
| 412 tp->GetColor(ThemeProperties::COLOR_TOOLBAR_SEPARATOR); | 424 kClientEdgeThickness, 0); |
| 413 if (ui::MaterialDesignController::IsModeMaterial()) { | 425 canvas->FillRect(toolbar_bounds, separator_color); |
| 414 toolbar_bounds.Inset(kClientEdgeThickness, 0); | |
| 415 BrowserView::Paint1pxHorizontalLine(canvas, separator_color, | |
| 416 toolbar_bounds); | |
| 417 } else { | |
| 418 toolbar_bounds.Inset(kClientEdgeThickness, h - kClientEdgeThickness, | |
| 419 kClientEdgeThickness, 0); | |
| 420 canvas->FillRect(toolbar_bounds, separator_color); | |
| 421 } | |
| 422 } | 426 } |
| 423 | 427 |
| 424 void GlassBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) { | 428 void GlassBrowserFrameView::PaintClientEdge(gfx::Canvas* canvas) { |
| 429 gfx::Rect client_bounds = CalculateClientAreaBounds(); |
| 430 int y = client_bounds.y(); |
| 431 const bool normal_mode = browser_view()->IsTabStripVisible(); |
| 425 ui::ThemeProvider* tp = GetThemeProvider(); | 432 ui::ThemeProvider* tp = GetThemeProvider(); |
| 426 int y = frame()->client_view()->y(); | 433 const SkColor toolbar_color = normal_mode ? |
| 434 tp->GetColor(ThemeProperties::COLOR_TOOLBAR) : |
| 435 ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_TOOLBAR); |
| 427 | 436 |
| 428 gfx::Rect client_bounds = CalculateClientAreaBounds(); | 437 const gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); |
| 438 if (!normal_mode) { |
| 439 // The toolbar isn't going to draw a top edge for us, so draw one ourselves. |
| 440 if (IsToolbarVisible()) |
| 441 y += toolbar_bounds.y() + kClientEdgeThickness; |
| 442 client_bounds.set_y(y); |
| 443 client_bounds.Inset(-kClientEdgeThickness, -kClientEdgeThickness, |
| 444 -kClientEdgeThickness, client_bounds.height()); |
| 445 canvas->FillRect(client_bounds, toolbar_color); |
| 446 |
| 447 // Popup and app windows don't custom-draw any other edges, so we're done. |
| 448 return; |
| 449 } |
| 450 |
| 451 // In maximized mode, the only edge to draw is the top one, so we're done. |
| 452 if (frame()->IsMaximized()) |
| 453 return; |
| 454 |
| 429 const int x = client_bounds.x(); | 455 const int x = client_bounds.x(); |
| 456 y += toolbar_bounds.bottom(); // The side edges start below the toolbar. |
| 430 const int w = client_bounds.width(); | 457 const int w = client_bounds.width(); |
| 431 const int right = client_bounds.right(); | 458 const int right = client_bounds.right(); |
| 432 const SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR); | |
| 433 | |
| 434 // The client edges start below the toolbar. | |
| 435 y += browser_view()->GetToolbarBounds().bottom(); | |
| 436 | |
| 437 const int bottom = std::max(y, height() - NonClientBorderThickness(false)); | 459 const int bottom = std::max(y, height() - NonClientBorderThickness(false)); |
| 438 int height = bottom - y; | 460 const int height = bottom - y; |
| 439 | 461 |
| 440 // Draw the client edge images. | 462 // Draw the client edge images. |
| 441 gfx::ImageSkia* right_image = tp->GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE); | 463 gfx::ImageSkia* right_image = tp->GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE); |
| 442 const int img_w = right_image->width(); | 464 const int img_w = right_image->width(); |
| 443 canvas->TileImageInt(*right_image, right, y, img_w, height); | 465 canvas->TileImageInt(*right_image, right, y, img_w, height); |
| 444 canvas->DrawImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER), | 466 canvas->DrawImageInt(*tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER), |
| 445 right, bottom); | 467 right, bottom); |
| 446 gfx::ImageSkia* bottom_image = | 468 gfx::ImageSkia* bottom_image = |
| 447 tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER); | 469 tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER); |
| 448 canvas->TileImageInt(*bottom_image, x, bottom, w, bottom_image->height()); | 470 canvas->TileImageInt(*bottom_image, x, bottom, w, bottom_image->height()); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 static bool initialized = false; | 642 static bool initialized = false; |
| 621 if (!initialized) { | 643 if (!initialized) { |
| 622 for (int i = 0; i < kThrobberIconCount; ++i) { | 644 for (int i = 0; i < kThrobberIconCount; ++i) { |
| 623 throbber_icons_[i] = | 645 throbber_icons_[i] = |
| 624 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); | 646 ui::LoadThemeIconFromResourcesDataDLL(IDI_THROBBER_01 + i); |
| 625 DCHECK(throbber_icons_[i]); | 647 DCHECK(throbber_icons_[i]); |
| 626 } | 648 } |
| 627 initialized = true; | 649 initialized = true; |
| 628 } | 650 } |
| 629 } | 651 } |
| OLD | NEW |