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

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

Issue 1430553004: Correctly align tab and toolbar backgrounds with the frame background. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix errors, better comments Created 5 years, 1 month 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
« no previous file with comments | « chrome/browser/ui/views/tabs/tab.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 5 #include "chrome/browser/ui/views/tabs/tab.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/alias.h" 10 #include "base/debug/alias.h"
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 int Tab::GetPinnedWidth() { 618 int Tab::GetPinnedWidth() {
619 return GetMinimumInactiveSize().width() + 619 return GetMinimumInactiveSize().width() +
620 GetLayoutConstant(TAB_PINNED_CONTENT_WIDTH); 620 GetLayoutConstant(TAB_PINNED_CONTENT_WIDTH);
621 } 621 }
622 622
623 // static 623 // static
624 int Tab::GetImmersiveHeight() { 624 int Tab::GetImmersiveHeight() {
625 return kImmersiveTabHeight; 625 return kImmersiveTabHeight;
626 } 626 }
627 627
628 // static
629 int Tab::GetYOffsetForActiveTabBackground() {
630 // The computed value here is strangely less than the height of the area atop
631 // the tab that doesn't get a background painted; otherwise, we could compute
632 // the value by simply using GetLayoutInsets(TAB).top(). My suspicion is that
633 // originally there was some sort of off-by-one error in how this background
634 // was painted, and theme authors compensated; now we're stuck perpetuating it
635 // as a result.
636 return -GetLayoutConstant(TAB_TOP_EXCLUSION_HEIGHT) - 1;
637 }
638
628 //////////////////////////////////////////////////////////////////////////////// 639 ////////////////////////////////////////////////////////////////////////////////
629 // Tab, AnimationDelegate overrides: 640 // Tab, AnimationDelegate overrides:
630 641
631 void Tab::AnimationProgressed(const gfx::Animation* animation) { 642 void Tab::AnimationProgressed(const gfx::Animation* animation) {
632 // Ignore if the pulse animation is being performed on active tab because 643 // Ignore if the pulse animation is being performed on active tab because
633 // it repaints the same image. See |Tab::PaintTabBackground()|. 644 // it repaints the same image. See |Tab::PaintTabBackground()|.
634 if (animation == pulse_animation_.get() && IsActive()) 645 if (animation == pulse_animation_.get() && IsActive())
635 return; 646 return;
636 SchedulePaint(); 647 SchedulePaint();
637 } 648 }
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 bar_rect.x(), 0, left_eye_width, kImmersiveBarHeight); 1134 bar_rect.x(), 0, left_eye_width, kImmersiveBarHeight);
1124 canvas->FillRect(left_eye_rect, kEyeColor); 1135 canvas->FillRect(left_eye_rect, kEyeColor);
1125 } 1136 }
1126 } 1137 }
1127 } 1138 }
1128 1139
1129 void Tab::PaintTabBackground(gfx::Canvas* canvas) { 1140 void Tab::PaintTabBackground(gfx::Canvas* canvas) {
1130 const int kActiveTabFillId = IDR_THEME_TOOLBAR; 1141 const int kActiveTabFillId = IDR_THEME_TOOLBAR;
1131 const bool has_custom_image = 1142 const bool has_custom_image =
1132 GetThemeProvider()->HasCustomImage(kActiveTabFillId); 1143 GetThemeProvider()->HasCustomImage(kActiveTabFillId);
1144 const int y_offset = GetYOffsetForActiveTabBackground();
1133 if (IsActive()) { 1145 if (IsActive()) {
1134 PaintTabBackgroundUsingFillId(canvas, true, kActiveTabFillId, 1146 PaintTabBackgroundUsingFillId(canvas, true, kActiveTabFillId,
1135 has_custom_image, 0); 1147 has_custom_image, y_offset);
1136 } else { 1148 } else {
1137 if (pinned_title_change_animation_ && 1149 if (pinned_title_change_animation_ &&
1138 pinned_title_change_animation_->is_animating()) 1150 pinned_title_change_animation_->is_animating())
1139 PaintInactiveTabBackgroundWithTitleChange(canvas); 1151 PaintInactiveTabBackgroundWithTitleChange(canvas);
1140 else 1152 else
1141 PaintInactiveTabBackground(canvas); 1153 PaintInactiveTabBackground(canvas);
1142 1154
1143 const double throb_value = GetThrobValue(); 1155 const double throb_value = GetThrobValue();
1144 if (throb_value > 0) { 1156 if (throb_value > 0) {
1145 canvas->SaveLayerAlpha(gfx::ToRoundedInt(throb_value * 0xff), 1157 canvas->SaveLayerAlpha(gfx::ToRoundedInt(throb_value * 0xff),
1146 GetLocalBounds()); 1158 GetLocalBounds());
1147 PaintTabBackgroundUsingFillId(canvas, true, kActiveTabFillId, 1159 PaintTabBackgroundUsingFillId(canvas, true, kActiveTabFillId,
1148 has_custom_image, 0); 1160 has_custom_image, y_offset);
1149 canvas->Restore(); 1161 canvas->Restore();
1150 } 1162 }
1151 } 1163 }
1152 } 1164 }
1153 1165
1154 void Tab::PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas) { 1166 void Tab::PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas) {
1155 const int kPinnedTitleChangeGradientRadius = 20; 1167 const int kPinnedTitleChangeGradientRadius = 20;
1156 const float radius = kPinnedTitleChangeGradientRadius; 1168 const float radius = kPinnedTitleChangeGradientRadius;
1157 double x = radius; 1169 double x = radius;
1158 int alpha = 255; 1170 int alpha = 255;
(...skipping 21 matching lines...) Expand all
1180 bool has_custom_image; 1192 bool has_custom_image;
1181 int fill_id = controller_->GetBackgroundResourceId(&has_custom_image); 1193 int fill_id = controller_->GetBackgroundResourceId(&has_custom_image);
1182 // Explicitly map the id so we cache correctly. 1194 // Explicitly map the id so we cache correctly.
1183 const chrome::HostDesktopType host_desktop_type = GetHostDesktopType(this); 1195 const chrome::HostDesktopType host_desktop_type = GetHostDesktopType(this);
1184 fill_id = chrome::MapThemeImage(host_desktop_type, fill_id); 1196 fill_id = chrome::MapThemeImage(host_desktop_type, fill_id);
1185 1197
1186 // If the theme is providing a custom background image, then its top edge 1198 // If the theme is providing a custom background image, then its top edge
1187 // should be at the top of the tab. Otherwise, we assume that the background 1199 // should be at the top of the tab. Otherwise, we assume that the background
1188 // image is a composited foreground + frame image. 1200 // image is a composited foreground + frame image.
1189 const int y_offset = GetThemeProvider()->HasCustomImage(fill_id) ? 1201 const int y_offset = GetThemeProvider()->HasCustomImage(fill_id) ?
1190 0 : background_offset_.y(); 1202 -GetLayoutConstant(TAB_TOP_EXCLUSION_HEIGHT) : background_offset_.y();
1191 1203
1192 // We only cache the image when it's the default image and we're not hovered, 1204 // We only cache the image when it's the default image and we're not hovered,
1193 // to avoid caching a background image that isn't the same for all tabs. 1205 // to avoid caching a background image that isn't the same for all tabs.
1194 if (!has_custom_image && !hover_controller_.ShouldDraw()) { 1206 if (!has_custom_image && !hover_controller_.ShouldDraw()) {
1195 ui::ScaleFactor scale_factor = 1207 ui::ScaleFactor scale_factor =
1196 ui::GetSupportedScaleFactor(canvas->image_scale()); 1208 ui::GetSupportedScaleFactor(canvas->image_scale());
1197 gfx::ImageSkia cached_image(GetCachedImage(fill_id, size(), scale_factor)); 1209 gfx::ImageSkia cached_image(GetCachedImage(fill_id, size(), scale_factor));
1198 if (cached_image.width() == 0) { 1210 if (cached_image.width() == 0) {
1199 gfx::Canvas tmp_canvas(size(), canvas->image_scale(), false); 1211 gfx::Canvas tmp_canvas(size(), canvas->image_scale(), false);
1200 PaintTabBackgroundUsingFillId(&tmp_canvas, false, fill_id, false, 1212 PaintTabBackgroundUsingFillId(&tmp_canvas, false, fill_id, false,
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 const gfx::ImageSkia& image) { 1553 const gfx::ImageSkia& image) {
1542 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); 1554 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE);
1543 ImageCacheEntry entry; 1555 ImageCacheEntry entry;
1544 entry.resource_id = resource_id; 1556 entry.resource_id = resource_id;
1545 entry.scale_factor = scale_factor; 1557 entry.scale_factor = scale_factor;
1546 entry.image = image; 1558 entry.image = image;
1547 image_cache_->push_front(entry); 1559 image_cache_->push_front(entry);
1548 if (image_cache_->size() > kMaxImageCacheSize) 1560 if (image_cache_->size() > kMaxImageCacheSize)
1549 image_cache_->pop_back(); 1561 image_cache_->pop_back();
1550 } 1562 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698