diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-26 18:25:06 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-26 18:25:06 +0000 |
commit | 5097e2d21a11e4f29875c2d66489832311e5038f (patch) | |
tree | ad1b5f2783c8f91ff6d02fb8e78bf6f9267028d7 | |
parent | 5af129a22b949932f6d856e833b321db916968fe (diff) | |
download | chromium_src-5097e2d21a11e4f29875c2d66489832311e5038f.zip chromium_src-5097e2d21a11e4f29875c2d66489832311e5038f.tar.gz chromium_src-5097e2d21a11e4f29875c2d66489832311e5038f.tar.bz2 |
ui/gfx: Refactor favicon_size.h
- Put it into a gfx namespace.
- Define the constant into the source file instead.
- Rename the function from calc_favicon_target_size to CalculateFaviconTargetSize,
so it matches with our style guide.
- Move the implementation of the function to the source file.
R=sky@chromium.org
Review URL: http://codereview.chromium.org/8037011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102760 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/extension_icon_manager.cc | 13 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_web_ui.cc | 2 | ||||
-rw-r--r-- | chrome/browser/favicon/favicon_handler.cc | 2 | ||||
-rw-r--r-- | chrome/browser/favicon/favicon_handler.h | 2 | ||||
-rw-r--r-- | chrome/browser/favicon/favicon_handler_unittest.cc | 14 | ||||
-rw-r--r-- | chrome/browser/importer/importer_util.cc | 8 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url.cc | 8 | ||||
-rw-r--r-- | chrome/browser/tab_contents/render_view_context_menu.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc | 22 | ||||
-rw-r--r-- | chrome/browser/ui/touch/tabs/touch_tab_strip_controller.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/views/tab_icon_view.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ui/views/tabs/side_tab.cc | 7 | ||||
-rw-r--r-- | chrome/browser/ui/views/tabs/tab.cc | 4 | ||||
-rw-r--r-- | chrome/renderer/chrome_render_view_observer.cc | 3 | ||||
-rw-r--r-- | ui/gfx/favicon_size.cc | 25 | ||||
-rw-r--r-- | ui/gfx/favicon_size.h | 21 | ||||
-rw-r--r-- | ui/ui.gyp | 1 | ||||
-rw-r--r-- | views/controls/table/native_table_win.cc | 3 | ||||
-rw-r--r-- | views/controls/table/table_view.cc | 3 |
19 files changed, 86 insertions, 66 deletions
diff --git a/chrome/browser/extensions/extension_icon_manager.cc b/chrome/browser/extensions/extension_icon_manager.cc index 8874209..3e93223 100644 --- a/chrome/browser/extensions/extension_icon_manager.cc +++ b/chrome/browser/extensions/extension_icon_manager.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. @@ -54,7 +54,7 @@ void ExtensionIconManager::LoadIcon(const Extension* extension) { pending_icons_.insert(extension->id()); image_tracker_.LoadImage(extension, icon_resource, - gfx::Size(kFaviconSize, kFaviconSize), + gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize), ImageLoadingTracker::CACHE); } } @@ -68,8 +68,8 @@ const SkBitmap& ExtensionIconManager::GetIcon(const std::string& extension_id) { result = &default_icon_; } DCHECK(result); - DCHECK_EQ(kFaviconSize + padding_.width(), result->width()); - DCHECK_EQ(kFaviconSize + padding_.height(), result->height()); + DCHECK_EQ(gfx::kFaviconSize + padding_.width(), result->width()); + DCHECK_EQ(gfx::kFaviconSize + padding_.height(), result->height()); return *result; } @@ -106,10 +106,11 @@ void ExtensionIconManager::EnsureDefaultIcon() { SkBitmap ExtensionIconManager::ApplyTransforms(const SkBitmap& source) { SkBitmap result = source; - if (result.width() != kFaviconSize || result.height() != kFaviconSize) { + if (result.width() != gfx::kFaviconSize || + result.height() != gfx::kFaviconSize) { result = skia::ImageOperations::Resize( result, skia::ImageOperations::RESIZE_LANCZOS3, - kFaviconSize, kFaviconSize); + gfx::kFaviconSize, gfx::kFaviconSize); } if (monochrome_) { diff --git a/chrome/browser/extensions/extension_web_ui.cc b/chrome/browser/extensions/extension_web_ui.cc index 2c84aac..ccb77d5 100644 --- a/chrome/browser/extensions/extension_web_ui.cc +++ b/chrome/browser/extensions/extension_web_ui.cc @@ -77,7 +77,7 @@ class ExtensionWebUIImageLoadingTracker : public ImageLoadingTracker::Observer { ExtensionIconSet::MATCH_EXACTLY); tracker_.LoadImage(extension_, icon_resource, - gfx::Size(kFaviconSize, kFaviconSize), + gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize), ImageLoadingTracker::DONT_CACHE); } else { ForwardResult(NULL); diff --git a/chrome/browser/favicon/favicon_handler.cc b/chrome/browser/favicon/favicon_handler.cc index 835dc98..b14bf9b 100644 --- a/chrome/browser/favicon/favicon_handler.cc +++ b/chrome/browser/favicon/favicon_handler.cc @@ -440,7 +440,7 @@ gfx::Image FaviconHandler::ResizeFaviconIfNeeded(const gfx::Image& image) { int width = bitmap.width(); int height = bitmap.height(); if (width > 0 && height > 0) { - calc_favicon_target_size(&width, &height); + gfx::CalculateFaviconTargetSize(&width, &height); return gfx::Image(new SkBitmap( skia::ImageOperations::Resize( bitmap, skia::ImageOperations::RESIZE_LANCZOS3, diff --git a/chrome/browser/favicon/favicon_handler.h b/chrome/browser/favicon/favicon_handler.h index b2a462d..ccdae05 100644 --- a/chrome/browser/favicon/favicon_handler.h +++ b/chrome/browser/favicon/favicon_handler.h @@ -222,7 +222,7 @@ class FaviconHandler { // Returns the preferred_icon_size according icon_types_, 0 means no // preference. int preferred_icon_size() { - return icon_types_ == history::FAVICON ? kFaviconSize : 0; + return icon_types_ == history::FAVICON ? gfx::kFaviconSize : 0; } // Used for history requests. diff --git a/chrome/browser/favicon/favicon_handler_unittest.cc b/chrome/browser/favicon/favicon_handler_unittest.cc index 91ef6f2..3eba39a 100644 --- a/chrome/browser/favicon/favicon_handler_unittest.cc +++ b/chrome/browser/favicon/favicon_handler_unittest.cc @@ -331,7 +331,7 @@ TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { history_handler->favicon_data_.expired = false; history_handler->favicon_data_.icon_url = icon_url; scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); - FillBitmap(kFaviconSize, kFaviconSize, &data->data()); + FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); history_handler->favicon_data_.image_data = data; // Send history response. @@ -400,7 +400,7 @@ TEST_F(FaviconHandlerTest, DownloadFavicon) { ASSERT_TRUE(download_handler); // Verify the download request. EXPECT_EQ(icon_url, download_handler->image_url_); - EXPECT_EQ(kFaviconSize, download_handler->image_size_); + EXPECT_EQ(gfx::kFaviconSize, download_handler->image_size_); // Reset the history_handler to verify whether favicon is set. helper.set_history_handler(NULL); @@ -446,7 +446,7 @@ TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { history_handler->favicon_data_.expired = false; history_handler->favicon_data_.icon_url = icon_url; scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); - FillBitmap(kFaviconSize, kFaviconSize, &data->data()); + FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); history_handler->favicon_data_.image_data = data; // Send history response. @@ -488,7 +488,7 @@ TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { ASSERT_TRUE(download_handler); // Verify the download request. EXPECT_EQ(new_icon_url, download_handler->image_url_); - EXPECT_EQ(kFaviconSize, download_handler->image_size_); + EXPECT_EQ(gfx::kFaviconSize, download_handler->image_size_); // Reset the history_handler to verify whether favicon is set. helper.set_history_handler(NULL); @@ -534,7 +534,7 @@ TEST_F(FaviconHandlerTest, UpdateFavicon) { history_handler->favicon_data_.expired = false; history_handler->favicon_data_.icon_url = icon_url; scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); - FillBitmap(kFaviconSize, kFaviconSize, &data->data()); + FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); history_handler->favicon_data_.image_data = data; // Send history response. @@ -677,7 +677,7 @@ TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { history_handler->favicon_data_.expired = true; history_handler->favicon_data_.icon_url = new_icon_url; scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); - FillBitmap(kFaviconSize, kFaviconSize, &data->data()); + FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); history_handler->favicon_data_.image_data = data; history_handler->InvokeCallback(); @@ -807,7 +807,7 @@ TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { handler->favicon_data_.icon_type = history::TOUCH_ICON; handler->favicon_data_.icon_url = latest_icon_url; scoped_refptr<RefCountedBytes> data = new RefCountedBytes(); - FillBitmap(kFaviconSize, kFaviconSize, &data->data()); + FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); handler->favicon_data_.image_data = data; handler->InvokeCallback(); diff --git a/chrome/browser/importer/importer_util.cc b/chrome/browser/importer/importer_util.cc index a5484c0..c0eea4a 100644 --- a/chrome/browser/importer/importer_util.cc +++ b/chrome/browser/importer/importer_util.cc @@ -16,16 +16,18 @@ bool ReencodeFavicon(const unsigned char* src_data, size_t src_len, std::vector<unsigned char>* png_data) { // Decode the favicon using WebKit's image decoder. - webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize)); + webkit_glue::ImageDecoder decoder( + gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize)); SkBitmap decoded = decoder.Decode(src_data, src_len); if (decoded.empty()) return false; // Unable to decode. - if (decoded.width() != kFaviconSize || decoded.height() != kFaviconSize) { + if (decoded.width() != gfx::kFaviconSize || + decoded.height() != gfx::kFaviconSize) { // The bitmap is not the correct size, re-sample. int new_width = decoded.width(); int new_height = decoded.height(); - calc_favicon_target_size(&new_width, &new_height); + gfx::CalculateFaviconTargetSize(&new_width, &new_height); decoded = skia::ImageOperations::Resize( decoded, skia::ImageOperations::RESIZE_LANCZOS3, new_width, new_height); } diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc index 1084a03f..e8619d7 100644 --- a/chrome/browser/search_engines/template_url.cc +++ b/chrome/browser/search_engines/template_url.cc @@ -703,7 +703,7 @@ void TemplateURL::SetFaviconURL(const GURL& url) { for (std::vector<ImageRef>::iterator i = image_refs_.begin(); i != image_refs_.end(); ++i) { if (i->type == "image/x-icon" && - i->width == kFaviconSize && i->height == kFaviconSize) { + i->width == gfx::kFaviconSize && i->height == gfx::kFaviconSize) { if (!url.is_valid()) image_refs_.erase(i); else @@ -714,8 +714,8 @@ void TemplateURL::SetFaviconURL(const GURL& url) { // Don't have one yet, add it. if (url.is_valid()) { add_image_ref( - TemplateURL::ImageRef("image/x-icon", kFaviconSize, - kFaviconSize, url)); + TemplateURL::ImageRef( + "image/x-icon", gfx::kFaviconSize, gfx::kFaviconSize, url)); } } @@ -723,7 +723,7 @@ GURL TemplateURL::GetFaviconURL() const { for (std::vector<ImageRef>::const_iterator i = image_refs_.begin(); i != image_refs_.end(); ++i) { if ((i->type == "image/x-icon" || i->type == "image/vnd.microsoft.icon") - && i->width == kFaviconSize && i->height == kFaviconSize) { + && i->width == gfx::kFaviconSize && i->height == gfx::kFaviconSize) { return i->url; } } diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index 0099b90..65b1de9 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -461,8 +461,8 @@ void RenderViewContextMenu::SetExtensionIcon(const std::string& extension_id) { DCHECK_GE(index, 0); const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); - DCHECK(icon.width() == kFaviconSize); - DCHECK(icon.height() == kFaviconSize); + DCHECK(icon.width() == gfx::kFaviconSize); + DCHECK(icon.height() == gfx::kFaviconSize); menu_model_.SetIcon(index, icon); } diff --git a/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc b/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc index fa0ae68..cca072f 100644 --- a/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc +++ b/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc @@ -462,7 +462,7 @@ gfx::Size TabRendererGtk::GetMinimumUnselectedSize() { // static gfx::Size TabRendererGtk::GetMinimumSelectedSize() { gfx::Size minimum_size = GetMinimumUnselectedSize(); - minimum_size.set_width(kLeftPadding + kFaviconSize + kRightPadding); + minimum_size.set_width(kLeftPadding + gfx::kFaviconSize + kRightPadding); return minimum_size; } @@ -482,7 +482,7 @@ int TabRendererGtk::GetMiniWidth() { int TabRendererGtk::GetContentHeight() { // The height of the content of the Tab is the largest of the favicon, // the title text and the close button graphic. - int content_height = std::max(kFaviconSize, title_font_height_); + int content_height = std::max(gfx::kFaviconSize, title_font_height_); return std::max(content_height, close_button_height_); } @@ -677,15 +677,15 @@ void TabRendererGtk::Layout() { // Size the Favicon. showing_icon_ = ShouldShowIcon(); if (showing_icon_) { - int favicon_top = kTopPadding + (content_height - kFaviconSize) / 2; + int favicon_top = kTopPadding + (content_height - gfx::kFaviconSize) / 2; favicon_bounds_.SetRect(local_bounds.x(), favicon_top, - kFaviconSize, kFaviconSize); + gfx::kFaviconSize, gfx::kFaviconSize); if ((mini() || data_.animating_mini_change) && bounds_.width() < kMiniTabRendererAsNormalTabWidth) { int mini_delta = kMiniTabRendererAsNormalTabWidth - GetMiniWidth(); int ideal_delta = bounds_.width() - GetMiniWidth(); if (ideal_delta < mini_delta) { - int ideal_x = (GetMiniWidth() - kFaviconSize) / 2; + int ideal_x = (GetMiniWidth() - gfx::kFaviconSize) / 2; int x = favicon_bounds_.x() + static_cast<int>( (1 - static_cast<float>(ideal_delta) / static_cast<float>(mini_delta)) * @@ -839,7 +839,7 @@ void TabRendererGtk::PaintIcon(gfx::Canvas* canvas) { crashed_favicon->height(), favicon_bounds_.x(), favicon_bounds_.y() + favicon_hiding_offset_, - kFaviconSize, kFaviconSize, + gfx::kFaviconSize, gfx::kFaviconSize, true); } else { if (!data_.favicon.isNull()) { @@ -853,9 +853,9 @@ void TabRendererGtk::PaintIcon(gfx::Canvas* canvas) { // larger than the standard favicon. int faviconHeightOffset = data_.app ? -2 : 0; int faviconWidthDelta = data_.app ? - data_.favicon.width() - kFaviconSize : 0; + data_.favicon.width() - gfx::kFaviconSize : 0; int faviconHeightDelta = data_.app ? - data_.favicon.height() - kFaviconSize : 0; + data_.favicon.height() - gfx::kFaviconSize : 0; // TODO(pkasting): Use code in tab_icon_view.cc:PaintIcon() (or switch // to using that class to render the favicon). @@ -866,8 +866,8 @@ void TabRendererGtk::PaintIcon(gfx::Canvas* canvas) { favicon_bounds_.y() + faviconHeightOffset - faviconHeightDelta/2 + favicon_hiding_offset_, - kFaviconSize + faviconWidthDelta, - kFaviconSize + faviconHeightDelta, + gfx::kFaviconSize + faviconWidthDelta, + gfx::kFaviconSize + faviconHeightDelta, true); } } @@ -987,7 +987,7 @@ void TabRendererGtk::PaintLoadingAnimation(gfx::Canvas* canvas) { int TabRendererGtk::IconCapacity() const { if (height() < GetMinimumUnselectedSize().height()) return 0; - return (width() - kLeftPadding - kRightPadding) / kFaviconSize; + return (width() - kLeftPadding - kRightPadding) / gfx::kFaviconSize; } bool TabRendererGtk::ShouldShowCloseBox() const { diff --git a/chrome/browser/ui/touch/tabs/touch_tab_strip_controller.cc b/chrome/browser/ui/touch/tabs/touch_tab_strip_controller.cc index c745d7d..215a0cb 100644 --- a/chrome/browser/ui/touch/tabs/touch_tab_strip_controller.cc +++ b/chrome/browser/ui/touch/tabs/touch_tab_strip_controller.cc @@ -105,8 +105,8 @@ void TouchTabStripController::SetTabRendererDataFromModel( // In the case where we do not have a touch icon we scale up the small // favicons (16x16) which originally are coming from NavigationEntry. - if (data->favicon.width() == kFaviconSize && - data->favicon.height() == kFaviconSize) { + if (data->favicon.width() == gfx::kFaviconSize && + data->favicon.height() == gfx::kFaviconSize) { data->favicon = skia::ImageOperations::Resize(data->favicon, skia::ImageOperations::RESIZE_BEST, TouchTab::kTouchTargetIconSize, TouchTab::kTouchTargetIconSize); diff --git a/chrome/browser/ui/views/tab_icon_view.cc b/chrome/browser/ui/views/tab_icon_view.cc index 7149733..6a72d7b 100644 --- a/chrome/browser/ui/views/tab_icon_view.cc +++ b/chrome/browser/ui/views/tab_icon_view.cc @@ -113,8 +113,8 @@ void TabIconView::PaintIcon(gfx::Canvas* canvas, float float_src_w = static_cast<float>(src_w); float float_src_h = static_cast<float>(src_h); float scalable_w, scalable_h; - if (src_w <= kFaviconSize && src_h <= kFaviconSize) { - scalable_w = scalable_h = kFaviconSize; + if (src_w <= gfx::kFaviconSize && src_h <= gfx::kFaviconSize) { + scalable_w = scalable_h = gfx::kFaviconSize; } else { scalable_w = float_src_w; scalable_h = float_src_h; @@ -151,5 +151,5 @@ void TabIconView::OnPaint(gfx::Canvas* canvas) { } gfx::Size TabIconView::GetPreferredSize() { - return gfx::Size(kFaviconSize, kFaviconSize); + return gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); } diff --git a/chrome/browser/ui/views/tabs/side_tab.cc b/chrome/browser/ui/views/tabs/side_tab.cc index 8f06495..dd1213a 100644 --- a/chrome/browser/ui/views/tabs/side_tab.cc +++ b/chrome/browser/ui/views/tabs/side_tab.cc @@ -26,7 +26,7 @@ const SkColor kTextColor = SK_ColorBLACK; const int kIconLeftPadding = 5; // Location the title starts at. -const int kTitleX = kIconLeftPadding + kFaviconSize + 5; +const int kTitleX = kIconLeftPadding + gfx::kFaviconSize + 5; }; //////////////////////////////////////////////////////////////////////////////// @@ -53,8 +53,9 @@ int SideTab::GetPreferredHeight() { void SideTab::Layout() { if (ShouldShowIcon()) { - int icon_y = (height() - kFaviconSize) / 2; - icon_bounds_.SetRect(kIconLeftPadding, icon_y, kFaviconSize, kFaviconSize); + int icon_y = (height() - gfx::kFaviconSize) / 2; + icon_bounds_.SetRect( + kIconLeftPadding, icon_y, gfx::kFaviconSize, gfx::kFaviconSize); } else { icon_bounds_ = gfx::Rect(); } diff --git a/chrome/browser/ui/views/tabs/tab.cc b/chrome/browser/ui/views/tabs/tab.cc index cfc2860..5bd6fef 100644 --- a/chrome/browser/ui/views/tabs/tab.cc +++ b/chrome/browser/ui/views/tabs/tab.cc @@ -43,7 +43,7 @@ static const int kCloseButtonVertFuzz = 0; static const int kTabIconSize = 32; static const int kCloseButtonHorzFuzz = -10; #else -static const int kTabIconSize = kFaviconSize; +static const int kTabIconSize = gfx::kFaviconSize; static const int kCloseButtonHorzFuzz = 5; #endif @@ -151,7 +151,7 @@ gfx::Size Tab::GetMinimumUnselectedSize() { // static gfx::Size Tab::GetMinimumSelectedSize() { gfx::Size minimum_size = GetMinimumUnselectedSize(); - minimum_size.set_width(kLeftPadding + kFaviconSize + kRightPadding); + minimum_size.set_width(kLeftPadding + gfx::kFaviconSize + kRightPadding); return minimum_size; } diff --git a/chrome/renderer/chrome_render_view_observer.cc b/chrome/renderer/chrome_render_view_observer.cc index 132b4cb..b913137 100644 --- a/chrome/renderer/chrome_render_view_observer.cc +++ b/chrome/renderer/chrome_render_view_observer.cc @@ -1000,7 +1000,8 @@ SkBitmap ChromeRenderViewObserver::ImageFromDataUrl(const GURL& url) const { std::string mime_type, char_set, data; if (net::DataURL::Parse(url, &mime_type, &char_set, &data) && !data.empty()) { // Decode the favicon using WebKit's image decoder. - webkit_glue::ImageDecoder decoder(gfx::Size(kFaviconSize, kFaviconSize)); + webkit_glue::ImageDecoder decoder( + gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize)); const unsigned char* src_data = reinterpret_cast<const unsigned char*>(&data[0]); diff --git a/ui/gfx/favicon_size.cc b/ui/gfx/favicon_size.cc new file mode 100644 index 0000000..d0ba48a --- /dev/null +++ b/ui/gfx/favicon_size.cc @@ -0,0 +1,25 @@ +// 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. + +#include "ui/gfx/favicon_size.h" + +namespace gfx { + +const int kFaviconSize = 16; + +void CalculateFaviconTargetSize(int* width, int* height) { + if (*width > kFaviconSize || *height > kFaviconSize) { + // Too big, resize it maintaining the aspect ratio. + float aspect_ratio = static_cast<float>(*width) / + static_cast<float>(*height); + *height = kFaviconSize; + *width = static_cast<int>(aspect_ratio * *height); + if (*width > kFaviconSize) { + *width = kFaviconSize; + *height = static_cast<int>(*width / aspect_ratio); + } + } +} + +} // namespace gfx diff --git a/ui/gfx/favicon_size.h b/ui/gfx/favicon_size.h index b7c9946..55bb6e35 100644 --- a/ui/gfx/favicon_size.h +++ b/ui/gfx/favicon_size.h @@ -6,29 +6,16 @@ #define UI_GFX_FAVICON_SIZE_H_ #pragma once -#include "base/compiler_specific.h" +namespace gfx { // Size (along each axis) of the favicon. -const int kFaviconSize = 16; +extern const int kFaviconSize; // If the width or height is bigger than the favicon size, a new width/height // is calculated and returned in width/height that maintains the aspect // ratio of the supplied values. -static void calc_favicon_target_size(int* width, int* height) ALLOW_UNUSED; +void CalculateFaviconTargetSize(int* width, int* height); -// static -void calc_favicon_target_size(int* width, int* height) { - if (*width > kFaviconSize || *height > kFaviconSize) { - // Too big, resize it maintaining the aspect ratio. - float aspect_ratio = static_cast<float>(*width) / - static_cast<float>(*height); - *height = kFaviconSize; - *width = static_cast<int>(aspect_ratio * *height); - if (*width > kFaviconSize) { - *width = kFaviconSize; - *height = static_cast<int>(*width / aspect_ratio); - } - } -} +} // namespace gfx #endif // UI_GFX_FAVICON_SIZE_H_ @@ -232,6 +232,7 @@ 'gfx/color_analysis.h', 'gfx/color_utils.cc', 'gfx/color_utils.h', + 'gfx/favicon_size.cc', 'gfx/favicon_size.h', 'gfx/font.h', 'gfx/font.cc', diff --git a/views/controls/table/native_table_win.cc b/views/controls/table/native_table_win.cc index d901906..6f8472c 100644 --- a/views/controls/table/native_table_win.cc +++ b/views/controls/table/native_table_win.cc @@ -540,7 +540,8 @@ LRESULT NativeTableWin::OnCustomDraw(NMLVCUSTOMDRAW* draw_info) { // view when they are 16x16 so we get an extra pixel of padding). canvas.DrawBitmapInt(image, 0, 0, image.width(), image.height(), - 1, 1, kFaviconSize, kFaviconSize, true); + 1, 1, + gfx::kFaviconSize, gfx::kFaviconSize, true); // Only paint the visible region of the icon. RECT to_draw = { intersection.left - icon_rect.left, diff --git a/views/controls/table/table_view.cc b/views/controls/table/table_view.cc index c8c1d59..ec81df8 100644 --- a/views/controls/table/table_view.cc +++ b/views/controls/table/table_view.cc @@ -1262,7 +1262,8 @@ LRESULT TableView::OnCustomDraw(NMLVCUSTOMDRAW* draw_info) { // view when they are 16x16 so we get an extra pixel of padding). canvas.DrawBitmapInt(image, 0, 0, image.width(), image.height(), - 1, 1, kFaviconSize, kFaviconSize, true); + 1, 1, + gfx::kFaviconSize, gfx::kFaviconSize, true); // Only paint the visible region of the icon. RECT to_draw = { intersection.left - icon_rect.left, |