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

Side by Side Diff: chrome/browser/ui/views/tabs/tab_strip.cc

Issue 18486007: Fix the misalignment on CrOS of the tab background images (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
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/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_strip_controller.h" 26 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h"
27 #include "chrome/browser/ui/views/tabs/tab_strip_observer.h" 27 #include "chrome/browser/ui/views/tabs/tab_strip_observer.h"
28 #include "chrome/browser/ui/views/tabs/tab_util.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"
36 #include "ui/base/dragdrop/drag_drop_types.h" 37 #include "ui/base/dragdrop/drag_drop_types.h"
37 #include "ui/base/l10n/l10n_util.h" 38 #include "ui/base/l10n/l10n_util.h"
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
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();
452 // This method assumes that the button is |width|x|height|.
453 DCHECK_EQ(width, NewTabButton::width());
454 DCHECK_EQ(height, NewTabButton::height());
446 455
447 // The canvas and mask has to use the same scale factor. 456 // The canvas and mask has to use the same scale factor.
448 if (!mask->HasRepresentation(scale_factor)) 457 if (!mask->HasRepresentation(scale_factor))
449 scale_factor = ui::SCALE_FACTOR_100P; 458 scale_factor = ui::SCALE_FACTOR_100P;
450 459
451 gfx::Canvas canvas(gfx::Size(width, height), scale_factor, false); 460 gfx::Canvas canvas(gfx::Size(width, height), scale_factor, false);
452 461
453 // For custom images the background starts at the top of the tab strip.
454 // Otherwise the background starts at the top of the frame.
455 gfx::ImageSkia* background =
456 GetThemeProvider()->GetImageSkiaNamed(background_id);
457 int offset_y = GetThemeProvider()->HasCustomImage(background_id) ?
458 0 : background_offset_.y();
459 462
460 // The new tab background is mirrored in RTL mode, but the theme background 463 // The new tab button is mirrored in RTL mode, but the button's background
461 // should never be mirrored. Mirror it here to compensate. 464 // should never be mirrored.
462 float x_scale = 1.0f; 465 if (base::i18n::IsRTL()) {
466 // Translate by |width| such that the same region is painted as if there was
467 // no flip.
468 canvas.Translate(gfx::Vector2d(width, 0));
469 canvas.Scale(-1, 1);
470 }
471
463 int x = GetMirroredX() + background_offset_.x(); 472 int x = GetMirroredX() + background_offset_.x();
464 if (base::i18n::IsRTL()) { 473 gfx::ImageSkia tiled_background = TabUtil::CreateTiledInactiveBackground(
465 x_scale = -1.0f; 474 GetThemeProvider(), background_id, background_overlay_id,
466 // Offset by |width| such that the same region is painted as if there was no 475 background_offset_.y(), x, newtab_button_v_offset(), width, height);
467 // flip. 476 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 477
473 if (alpha != 255) { 478 if (alpha != 255) {
474 SkPaint paint; 479 SkPaint paint;
475 paint.setColor(SkColorSetARGB(alpha, 255, 255, 255)); 480 paint.setColor(SkColorSetARGB(alpha, 255, 255, 255));
476 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); 481 paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
477 paint.setStyle(SkPaint::kFill_Style); 482 paint.setStyle(SkPaint::kFill_Style);
478 canvas.DrawRect(gfx::Rect(0, 0, width, height), paint); 483 canvas.DrawRect(gfx::Rect(0, 0, width, height), paint);
479 } 484 }
480 485
481 // White highlight on hover. 486 // White highlight on hover.
(...skipping 2224 matching lines...) Expand 10 before | Expand all | Expand 10 after
2706 if (!adjust_layout_) 2711 if (!adjust_layout_)
2707 return false; 2712 return false;
2708 2713
2709 #if !defined(OS_CHROMEOS) 2714 #if !defined(OS_CHROMEOS)
2710 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) 2715 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH)
2711 return false; 2716 return false;
2712 #endif 2717 #endif
2713 2718
2714 return true; 2719 return true;
2715 } 2720 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698