summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views
diff options
context:
space:
mode:
authoroshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-15 17:58:59 +0000
committeroshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-15 17:58:59 +0000
commitf4632f7de7b567858b71a3839ca7be22ccb7458a (patch)
tree95b78a50af4f8a197a2524e14147eb808bae668b /chrome/browser/ui/views
parentc291f5d7ea28c11aafebe68a5b90165ada2c7dc9 (diff)
downloadchromium_src-f4632f7de7b567858b71a3839ca7be22ccb7458a.zip
chromium_src-f4632f7de7b567858b71a3839ca7be22ccb7458a.tar.gz
chromium_src-f4632f7de7b567858b71a3839ca7be22ccb7458a.tar.bz2
Minimize the region to paint favicon/spinner/sad_favicon
Forces the size of favicon region to be 16x16 (given by kFavIconSize) Center the favicon in this region. BUG=none TEST=none Review URL: http://codereview.chromium.org/6517015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74970 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/views')
-rw-r--r--chrome/browser/ui/views/tabs/base_tab.cc94
-rw-r--r--chrome/browser/ui/views/tabs/base_tab.h12
-rw-r--r--chrome/browser/ui/views/tabs/side_tab.cc19
-rw-r--r--chrome/browser/ui/views/tabs/side_tab.h3
-rw-r--r--chrome/browser/ui/views/tabs/tab.cc28
-rw-r--r--chrome/browser/ui/views/tabs/tab.h5
6 files changed, 96 insertions, 65 deletions
diff --git a/chrome/browser/ui/views/tabs/base_tab.cc b/chrome/browser/ui/views/tabs/base_tab.cc
index 8fd7d3d..afc5ebc 100644
--- a/chrome/browser/ui/views/tabs/base_tab.cc
+++ b/chrome/browser/ui/views/tabs/base_tab.cc
@@ -70,6 +70,23 @@ class TabCloseButton : public views::ImageButton {
DISALLOW_COPY_AND_ASSIGN(TabCloseButton);
};
+// Draws the icon image at the center of |bounds|.
+void DrawIconCenter(gfx::Canvas* canvas,
+ const SkBitmap& image,
+ int image_offset,
+ int icon_width,
+ int icon_height,
+ const gfx::Rect& bounds,
+ bool filter) {
+ // Center the image within bounds.
+ int dst_x = bounds.x() - (icon_width - bounds.width()) / 2;
+ int dst_y = bounds.y() - (icon_height - bounds.height()) / 2;
+ canvas->DrawBitmapInt(image,
+ image_offset, 0, icon_width, icon_height,
+ dst_x, dst_y, icon_width, icon_height,
+ filter);
+}
+
} // namespace
// static
@@ -315,7 +332,7 @@ bool BaseTab::GetTooltipText(const gfx::Point& p, std::wstring* tooltip) {
return false;
// Only show the tooltip if the title is truncated.
- if (font_->GetStringWidth(data_.title) > title_bounds().width()) {
+ if (font_->GetStringWidth(data_.title) > GetTitleBounds().width()) {
*tooltip = UTF16ToWide(data_.title);
return true;
}
@@ -366,50 +383,48 @@ void BaseTab::AdvanceLoadingAnimation(TabRendererData::NetworkState old_state,
} else {
loading_animation_frame_ = 0;
}
- SchedulePaint();
+ ScheduleIconPaint();
}
-void BaseTab::PaintIcon(gfx::Canvas* canvas, int x, int y) {
- if (base::i18n::IsRTL()) {
- x = width() - x -
- (data().favicon.isNull() ? kFavIconSize : data().favicon.width());
- }
+void BaseTab::PaintIcon(gfx::Canvas* canvas) {
+ gfx::Rect bounds = GetIconBounds();
+ if (bounds.IsEmpty())
+ return;
+
+ // The size of bounds has to be kFavIconSize x kFavIconSize.
+ DCHECK_EQ(kFavIconSize, bounds.width());
+ DCHECK_EQ(kFavIconSize, bounds.height());
- int favicon_x = x;
- if (!data().favicon.isNull() && data().favicon.width() != kFavIconSize)
- favicon_x += (data().favicon.width() - kFavIconSize) / 2;
+ bounds.set_x(GetMirroredXForRect(bounds));
if (data().network_state != TabRendererData::NETWORK_STATE_NONE) {
ui::ThemeProvider* tp = GetThemeProvider();
SkBitmap frames(*tp->GetBitmapNamed(
(data().network_state == TabRendererData::NETWORK_STATE_WAITING) ?
IDR_THROBBER_WAITING : IDR_THROBBER));
- int image_size = frames.height();
- int image_offset = loading_animation_frame_ * image_size;
- int dst_y = (height() - image_size) / 2;
- canvas->DrawBitmapInt(frames, image_offset, 0, image_size,
- image_size, favicon_x, dst_y, image_size, image_size,
- false);
+
+ int icon_size = frames.height();
+ int image_offset = loading_animation_frame_ * icon_size;
+ DrawIconCenter(canvas, frames, image_offset,
+ icon_size, icon_size, bounds, false);
} else {
canvas->Save();
canvas->ClipRectInt(0, 0, width(), height());
if (should_display_crashed_favicon_) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
SkBitmap crashed_fav_icon(*rb.GetBitmapNamed(IDR_SAD_FAVICON));
- canvas->DrawBitmapInt(crashed_fav_icon, 0, 0, crashed_fav_icon.width(),
- crashed_fav_icon.height(), favicon_x,
- (height() - crashed_fav_icon.height()) / 2 + fav_icon_hiding_offset_,
- kFavIconSize, kFavIconSize, true);
+ bounds.set_y(bounds.y() + fav_icon_hiding_offset_);
+ DrawIconCenter(canvas, crashed_fav_icon, 0,
+ crashed_fav_icon.width(),
+ crashed_fav_icon.height(), bounds, true);
} else {
if (!data().favicon.isNull()) {
// TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch
// to using that class to render the favicon).
- int size = data().favicon.width();
- canvas->DrawBitmapInt(data().favicon, 0, 0,
- data().favicon.width(),
- data().favicon.height(),
- x, y + fav_icon_hiding_offset_, size, size,
- true);
+ DrawIconCenter(canvas, data().favicon, 0,
+ data().favicon.width(),
+ data().favicon.height(),
+ bounds, true);
}
}
canvas->Restore();
@@ -426,22 +441,22 @@ void BaseTab::PaintTitle(gfx::Canvas* canvas, SkColor title_color) {
} else {
Browser::FormatTitleForDisplay(&title);
}
-
+ const gfx::Rect& title_bounds = GetTitleBounds();
canvas->DrawStringInt(title, *font_, title_color,
- title_bounds().x(), title_bounds().y(),
- title_bounds().width(), title_bounds().height());
+ title_bounds.x(), title_bounds.y(),
+ title_bounds.width(), title_bounds.height());
}
void BaseTab::AnimationProgressed(const ui::Animation* animation) {
- SchedulePaint();
+ ScheduleIconPaint();
}
void BaseTab::AnimationCanceled(const ui::Animation* animation) {
- SchedulePaint();
+ ScheduleIconPaint();
}
void BaseTab::AnimationEnded(const ui::Animation* animation) {
- SchedulePaint();
+ ScheduleIconPaint();
}
void BaseTab::ButtonPressed(views::Button* sender, const views::Event& event) {
@@ -458,7 +473,7 @@ void BaseTab::ShowContextMenu(views::View* source,
void BaseTab::SetFavIconHidingOffset(int offset) {
fav_icon_hiding_offset_ = offset;
- SchedulePaint();
+ ScheduleIconPaint();
}
void BaseTab::DisplayCrashedFavIcon() {
@@ -486,6 +501,19 @@ bool BaseTab::IsPerformingCrashAnimation() const {
return crash_animation_.get() && crash_animation_->is_animating();
}
+void BaseTab::ScheduleIconPaint() {
+ gfx::Rect bounds = GetIconBounds();
+ if (bounds.IsEmpty())
+ return;
+
+ // Extends the area to the bottom when sad_favicon is
+ // animating.
+ if (IsPerformingCrashAnimation())
+ bounds.set_height(height() - bounds.y());
+ bounds.set_x(GetMirroredXForRect(bounds));
+ SchedulePaint(bounds, false);
+}
+
// static
void BaseTab::InitResources() {
static bool initialized = false;
diff --git a/chrome/browser/ui/views/tabs/base_tab.h b/chrome/browser/ui/views/tabs/base_tab.h
index 6d1f3ea..8a43f06 100644
--- a/chrome/browser/ui/views/tabs/base_tab.h
+++ b/chrome/browser/ui/views/tabs/base_tab.h
@@ -115,7 +115,7 @@ class BaseTab : public ui::AnimationDelegate,
views::ImageButton* close_button() const { return close_button_; }
// Paints the icon at the specified coordinates, mirrored for RTL if needed.
- void PaintIcon(gfx::Canvas* canvas, int x, int y);
+ void PaintIcon(gfx::Canvas* canvas);
void PaintTitle(gfx::Canvas* canvas, SkColor title_color);
// Overridden from AnimationDelegate:
@@ -132,8 +132,9 @@ class BaseTab : public ui::AnimationDelegate,
const gfx::Point& p,
bool is_mouse_gesture);
- // Returns the bounds of the title.
- virtual const gfx::Rect& title_bounds() const = 0;
+ // Returns the bounds of the title and icon.
+ virtual const gfx::Rect& GetTitleBounds() const = 0;
+ virtual const gfx::Rect& GetIconBounds() const = 0;
virtual int loading_animation_frame() const {
return loading_animation_frame_;
@@ -161,9 +162,12 @@ class BaseTab : public ui::AnimationDelegate,
void StartCrashAnimation();
void StopCrashAnimation();
- // Return true if the crash animation is currently running.
+ // Returns true if the crash animation is currently running.
bool IsPerformingCrashAnimation() const;
+ // Schedules repaint task for icon.
+ void ScheduleIconPaint();
+
static void InitResources();
// The controller.
diff --git a/chrome/browser/ui/views/tabs/side_tab.cc b/chrome/browser/ui/views/tabs/side_tab.cc
index 71efa38..e29eeeb 100644
--- a/chrome/browser/ui/views/tabs/side_tab.cc
+++ b/chrome/browser/ui/views/tabs/side_tab.cc
@@ -52,15 +52,8 @@ int SideTab::GetPreferredHeight() {
void SideTab::Layout() {
if (ShouldShowIcon()) {
- int icon_x = kIconLeftPadding;
int icon_y = (height() - kFavIconSize) / 2;
- int icon_size =
- !data().favicon.empty() ? data().favicon.width() : kFavIconSize;
- if (icon_size != kFavIconSize) {
- icon_x -= (icon_size - kFavIconSize) / 2;
- icon_y -= (icon_size - kFavIconSize) / 2;
- }
- icon_bounds_.SetRect(icon_x, icon_y, icon_size, icon_size);
+ icon_bounds_.SetRect(kIconLeftPadding, icon_y, kFavIconSize, kFavIconSize);
} else {
icon_bounds_ = gfx::Rect();
}
@@ -96,7 +89,7 @@ void SideTab::Paint(gfx::Canvas* canvas) {
}
if (ShouldShowIcon())
- PaintIcon(canvas, icon_bounds_.x(), icon_bounds_.y());
+ PaintIcon(canvas);
PaintTitle(canvas, kTextColor);
}
@@ -105,6 +98,14 @@ gfx::Size SideTab::GetPreferredSize() {
return gfx::Size(0, GetPreferredHeight());
}
+const gfx::Rect& SideTab::GetTitleBounds() const {
+ return title_bounds_;
+}
+
+const gfx::Rect& SideTab::GetIconBounds() const {
+ return icon_bounds_;
+}
+
bool SideTab::ShouldPaintHighlight() const {
return IsSelected() || !controller();
}
diff --git a/chrome/browser/ui/views/tabs/side_tab.h b/chrome/browser/ui/views/tabs/side_tab.h
index b0ac0a7..dde816b 100644
--- a/chrome/browser/ui/views/tabs/side_tab.h
+++ b/chrome/browser/ui/views/tabs/side_tab.h
@@ -26,7 +26,8 @@ class SideTab : public BaseTab {
virtual gfx::Size GetPreferredSize();
protected:
- virtual const gfx::Rect& title_bounds() const { return title_bounds_; }
+ virtual const gfx::Rect& GetTitleBounds() const;
+ virtual const gfx::Rect& GetIconBounds() const;
// Returns true if the selected highlight should be rendered.
virtual bool ShouldPaintHighlight() const;
diff --git a/chrome/browser/ui/views/tabs/tab.cc b/chrome/browser/ui/views/tabs/tab.cc
index 8230b89..9cb04d9 100644
--- a/chrome/browser/ui/views/tabs/tab.cc
+++ b/chrome/browser/ui/views/tabs/tab.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -163,6 +163,14 @@ int Tab::GetMiniWidth() {
////////////////////////////////////////////////////////////////////////////////
// Tab, protected:
+const gfx::Rect& Tab::GetTitleBounds() const {
+ return title_bounds_;
+}
+
+const gfx::Rect& Tab::GetIconBounds() const {
+ return favicon_bounds_;
+}
+
void Tab::DataChanged(const TabRendererData& old) {
if (data().blocked == old.blocked)
return;
@@ -227,23 +235,17 @@ void Tab::Layout() {
showing_icon_ = ShouldShowIcon();
if (showing_icon_) {
// Use the size of the favicon as apps use a bigger favicon size.
- int favicon_size =
- !data().favicon.empty() ? data().favicon.width() : kFavIconSize;
- int favicon_top = kTopPadding + content_height / 2 - favicon_size / 2;
+ int favicon_top = kTopPadding + content_height / 2 - kFavIconSize / 2;
int favicon_left = lb.x();
- if (favicon_size != kFavIconSize) {
- favicon_left -= (favicon_size - kFavIconSize) / 2;
- favicon_top -= kAppTapFaviconVerticalAdjustment;
- }
favicon_bounds_.SetRect(favicon_left, favicon_top,
- favicon_size, favicon_size);
+ kFavIconSize, kFavIconSize);
if (data().mini && width() < kMiniTabRendererAsNormalTabWidth) {
// Adjust the location of the favicon when transitioning from a normal
// tab to a mini-tab.
int mini_delta = kMiniTabRendererAsNormalTabWidth - GetMiniWidth();
int ideal_delta = width() - GetMiniWidth();
if (ideal_delta < mini_delta) {
- int ideal_x = (GetMiniWidth() - favicon_size) / 2;
+ int ideal_x = (GetMiniWidth() - kFavIconSize) / 2;
int x = favicon_bounds_.x() + static_cast<int>(
(1 - static_cast<float>(ideal_delta) /
static_cast<float>(mini_delta)) *
@@ -339,7 +341,7 @@ void Tab::GetHitTestMask(gfx::Path* path) const {
}
bool Tab::GetTooltipTextOrigin(const gfx::Point& p, gfx::Point* origin) {
- origin->set_x(title_bounds().x() + 10);
+ origin->set_x(title_bounds_.x() + 10);
origin->set_y(-views::TooltipManager::GetTooltipHeight() - 4);
return true;
}
@@ -354,10 +356,6 @@ void Tab::OnMouseMoved(const views::MouseEvent& e) {
////////////////////////////////////////////////////////////////////////////////
// Tab, private
-void Tab::PaintIcon(gfx::Canvas* canvas) {
- BaseTab::PaintIcon(canvas, favicon_bounds_.x(), favicon_bounds_.y());
-}
-
void Tab::PaintTabBackground(gfx::Canvas* canvas) {
if (IsSelected()) {
PaintActiveTabBackground(canvas);
diff --git a/chrome/browser/ui/views/tabs/tab.h b/chrome/browser/ui/views/tabs/tab.h
index f76615e..a5b6c98 100644
--- a/chrome/browser/ui/views/tabs/tab.h
+++ b/chrome/browser/ui/views/tabs/tab.h
@@ -56,9 +56,9 @@ class Tab : public BaseTab {
static int GetMiniWidth();
protected:
- virtual const gfx::Rect& title_bounds() const { return title_bounds_; }
-
// BaseTab overrides:
+ virtual const gfx::Rect& GetTitleBounds() const;
+ virtual const gfx::Rect& GetIconBounds() const;
virtual void DataChanged(const TabRendererData& old);
private:
@@ -77,7 +77,6 @@ class Tab : public BaseTab {
void PaintInactiveTabBackgroundWithTitleChange(gfx::Canvas* canvas);
void PaintInactiveTabBackground(gfx::Canvas* canvas);
void PaintActiveTabBackground(gfx::Canvas* canvas);
- void PaintIcon(gfx::Canvas* canvas);
SkBitmap DrawHoverGlowBitmap(int width, int height);
// Returns the number of favicon-size elements that can fit in the tab's