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/tabs/tab_strip.h" | 5 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windowsx.h> | 8 #include <windowsx.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <iterator> | 12 #include <iterator> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "chrome/browser/defaults.h" | 20 #include "chrome/browser/defaults.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/browser/ui/view_ids.h" | 22 #include "chrome/browser/ui/view_ids.h" |
23 #include "chrome/browser/ui/views/tabs/stacked_tab_strip_layout.h" | 23 #include "chrome/browser/ui/views/tabs/stacked_tab_strip_layout.h" |
24 #include "chrome/browser/ui/views/tabs/tab.h" | 24 #include "chrome/browser/ui/views/tabs/tab.h" |
25 #include "chrome/browser/ui/views/tabs/tab_drag_controller.h" | 25 #include "chrome/browser/ui/views/tabs/tab_drag_controller.h" |
| 26 #include "chrome/browser/ui/views/tabs/tab_paint_util.h" |
26 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h" | 27 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h" |
27 #include "chrome/browser/ui/views/tabs/tab_strip_observer.h" | 28 #include "chrome/browser/ui/views/tabs/tab_strip_observer.h" |
28 #include "chrome/browser/ui/views/touch_uma/touch_uma.h" | 29 #include "chrome/browser/ui/views/touch_uma/touch_uma.h" |
29 #include "content/public/browser/user_metrics.h" | 30 #include "content/public/browser/user_metrics.h" |
30 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
31 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
32 #include "ui/base/accessibility/accessible_view_state.h" | 33 #include "ui/base/accessibility/accessible_view_state.h" |
33 #include "ui/base/animation/animation_container.h" | 34 #include "ui/base/animation/animation_container.h" |
34 #include "ui/base/animation/throb_animation.h" | 35 #include "ui/base/animation/throb_animation.h" |
35 #include "ui/base/default_theme_provider.h" | 36 #include "ui/base/default_theme_provider.h" |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 407 |
407 bool NewTabButton::ShouldUseNativeFrame() const { | 408 bool NewTabButton::ShouldUseNativeFrame() const { |
408 return GetWidget() && | 409 return GetWidget() && |
409 GetWidget()->GetTopLevelWidget()->ShouldUseNativeFrame(); | 410 GetWidget()->GetTopLevelWidget()->ShouldUseNativeFrame(); |
410 } | 411 } |
411 | 412 |
412 gfx::ImageSkia NewTabButton::GetBackgroundImage( | 413 gfx::ImageSkia NewTabButton::GetBackgroundImage( |
413 views::CustomButton::ButtonState state, | 414 views::CustomButton::ButtonState state, |
414 ui::ScaleFactor scale_factor) const { | 415 ui::ScaleFactor scale_factor) const { |
415 int background_id = 0; | 416 int background_id = 0; |
| 417 int background_overlay_id = 0; |
416 if (ShouldUseNativeFrame()) { | 418 if (ShouldUseNativeFrame()) { |
417 background_id = IDR_THEME_TAB_BACKGROUND_V; | 419 background_id = IDR_THEME_TAB_BACKGROUND_V; |
| 420 background_overlay_id = IDR_THEME_TAB_BACKGROUND_V_OVERLAY; |
418 } else if (tab_strip_->controller()->IsIncognito()) { | 421 } else if (tab_strip_->controller()->IsIncognito()) { |
419 background_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO; | 422 background_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO; |
| 423 background_overlay_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO_OVERLAY; |
420 #if defined(OS_WIN) | 424 #if defined(OS_WIN) |
421 } else if (win8::IsSingleWindowMetroMode()) { | 425 } else if (win8::IsSingleWindowMetroMode()) { |
422 background_id = IDR_THEME_TAB_BACKGROUND_V; | 426 background_id = IDR_THEME_TAB_BACKGROUND_V; |
| 427 background_overlay_id = IDR_THEME_TAB_BACKGROUND_V_OVERLAY; |
423 #endif | 428 #endif |
424 } else { | 429 } else { |
425 background_id = IDR_THEME_TAB_BACKGROUND; | 430 background_id = IDR_THEME_TAB_BACKGROUND; |
| 431 background_overlay_id = IDR_THEME_TAB_BACKGROUND_OVERLAY; |
426 } | 432 } |
427 | 433 |
428 int alpha = 0; | 434 int alpha = 0; |
429 switch (state) { | 435 switch (state) { |
430 case views::CustomButton::STATE_NORMAL: | 436 case views::CustomButton::STATE_NORMAL: |
431 case views::CustomButton::STATE_HOVERED: | 437 case views::CustomButton::STATE_HOVERED: |
432 alpha = ShouldUseNativeFrame() ? kNativeFrameInactiveTabAlpha : 255; | 438 alpha = ShouldUseNativeFrame() ? kNativeFrameInactiveTabAlpha : 255; |
433 break; | 439 break; |
434 case views::CustomButton::STATE_PRESSED: | 440 case views::CustomButton::STATE_PRESSED: |
435 alpha = 145; | 441 alpha = 145; |
436 break; | 442 break; |
437 default: | 443 default: |
438 NOTREACHED(); | 444 NOTREACHED(); |
439 break; | 445 break; |
440 } | 446 } |
441 | 447 |
442 gfx::ImageSkia* mask = | 448 gfx::ImageSkia* mask = |
443 GetThemeProvider()->GetImageSkiaNamed(IDR_NEWTAB_BUTTON_MASK); | 449 GetThemeProvider()->GetImageSkiaNamed(IDR_NEWTAB_BUTTON_MASK); |
444 int height = mask->height(); | 450 int height = mask->height(); |
445 int width = mask->width(); | 451 int width = mask->width(); |
446 | 452 |
447 // The canvas and mask has to use the same scale factor. | 453 // The canvas and mask has to use the same scale factor. |
448 if (!mask->HasRepresentation(scale_factor)) | 454 if (!mask->HasRepresentation(scale_factor)) |
449 scale_factor = ui::SCALE_FACTOR_100P; | 455 scale_factor = ui::SCALE_FACTOR_100P; |
450 | 456 |
451 gfx::Canvas canvas(gfx::Size(width, height), scale_factor, false); | 457 gfx::Canvas canvas(gfx::Size(width, height), scale_factor, false); |
452 | 458 |
453 // For custom images the background starts at the top of the tab strip. | 459 // The new tab button is mirrored in RTL mode, but the button's background |
454 // Otherwise the background starts at the top of the frame. | 460 // should never be mirrored. |
455 gfx::ImageSkia* background = | 461 if (base::i18n::IsRTL()) { |
456 GetThemeProvider()->GetImageSkiaNamed(background_id); | 462 // Translate by |width| such that the same region is painted as if there was |
457 int offset_y = GetThemeProvider()->HasCustomImage(background_id) ? | 463 // no flip. |
458 0 : background_offset_.y(); | 464 canvas.Translate(gfx::Vector2d(width, 0)); |
| 465 canvas.Scale(-1, 1); |
| 466 } |
459 | 467 |
460 // The new tab background is mirrored in RTL mode, but the theme background | |
461 // should never be mirrored. Mirror it here to compensate. | |
462 float x_scale = 1.0f; | |
463 int x = GetMirroredX() + background_offset_.x(); | 468 int x = GetMirroredX() + background_offset_.x(); |
464 if (base::i18n::IsRTL()) { | 469 gfx::ImageSkia tiled_background = TabPaintUtil::CreateTiledInactiveBackground( |
465 x_scale = -1.0f; | 470 GetThemeProvider(), background_id, background_overlay_id, |
466 // Offset by |width| such that the same region is painted as if there was no | 471 background_offset_.y(), x, newtab_button_v_offset(), width, height); |
467 // flip. | 472 canvas.DrawImageInt(tiled_background, 0, 0); |
468 x += width; | |
469 } | |
470 canvas.TileImageInt(*background, x, newtab_button_v_offset() + offset_y, | |
471 x_scale, 1.0f, 0, 0, width, height); | |
472 | 473 |
473 if (alpha != 255) { | 474 if (alpha != 255) { |
474 SkPaint paint; | 475 SkPaint paint; |
475 paint.setColor(SkColorSetARGB(alpha, 255, 255, 255)); | 476 paint.setColor(SkColorSetARGB(alpha, 255, 255, 255)); |
476 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); | 477 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); |
477 paint.setStyle(SkPaint::kFill_Style); | 478 paint.setStyle(SkPaint::kFill_Style); |
478 canvas.DrawRect(gfx::Rect(0, 0, width, height), paint); | 479 canvas.DrawRect(gfx::Rect(0, 0, width, height), paint); |
479 } | 480 } |
480 | 481 |
481 // White highlight on hover. | 482 // White highlight on hover. |
(...skipping 2230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2712 if (!adjust_layout_) | 2713 if (!adjust_layout_) |
2713 return false; | 2714 return false; |
2714 | 2715 |
2715 #if !defined(OS_CHROMEOS) | 2716 #if !defined(OS_CHROMEOS) |
2716 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) | 2717 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) |
2717 return false; | 2718 return false; |
2718 #endif | 2719 #endif |
2719 | 2720 |
2720 return true; | 2721 return true; |
2721 } | 2722 } |
OLD | NEW |