summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/favicon/favicon_handler.cc2
-rw-r--r--chrome/browser/favicon/favicon_service.cc2
-rw-r--r--chrome/browser/favicon/favicon_util.cc2
-rw-r--r--chrome/browser/history/history_backend.cc2
-rw-r--r--chrome/browser/history/select_favicon_frames_unittest.cc6
-rw-r--r--chrome/browser/ui/views/create_application_shortcut_view.cc2
-rw-r--r--chrome/browser/web_applications/update_shortcut_worker_win.cc2
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--components/favicon_base.gypi3
-rw-r--r--components/favicon_base/DEPS3
-rw-r--r--components/favicon_base/select_favicon_frames.cc (renamed from chrome/browser/history/select_favicon_frames.cc)61
-rw-r--r--components/favicon_base/select_favicon_frames.h (renamed from chrome/browser/history/select_favicon_frames.h)8
12 files changed, 52 insertions, 43 deletions
diff --git a/chrome/browser/favicon/favicon_handler.cc b/chrome/browser/favicon/favicon_handler.cc
index 08487e0..f3330f7 100644
--- a/chrome/browser/favicon/favicon_handler.cc
+++ b/chrome/browser/favicon/favicon_handler.cc
@@ -14,7 +14,7 @@
#include "base/memory/ref_counted_memory.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/favicon/favicon_util.h"
-#include "chrome/browser/history/select_favicon_frames.h"
+#include "components/favicon_base/select_favicon_frames.h"
#include "content/public/browser/favicon_status.h"
#include "content/public/browser/navigation_entry.h"
#include "skia/ext/image_operations.h"
diff --git a/chrome/browser/favicon/favicon_service.cc b/chrome/browser/favicon/favicon_service.cc
index 8587a02..bca611a 100644
--- a/chrome/browser/favicon/favicon_service.cc
+++ b/chrome/browser/favicon/favicon_service.cc
@@ -10,11 +10,11 @@
#include "chrome/browser/history/history_backend.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
-#include "chrome/browser/history/select_favicon_frames.h"
#include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h"
#include "chrome/common/importer/imported_favicon_usage.h"
#include "chrome/common/url_constants.h"
#include "components/favicon_base/favicon_types.h"
+#include "components/favicon_base/select_favicon_frames.h"
#include "extensions/common/constants.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/codec/png_codec.h"
diff --git a/chrome/browser/favicon/favicon_util.cc b/chrome/browser/favicon/favicon_util.cc
index 9cd480e..652f805 100644
--- a/chrome/browser/favicon/favicon_util.cc
+++ b/chrome/browser/favicon/favicon_util.cc
@@ -4,8 +4,8 @@
#include "chrome/browser/favicon/favicon_util.h"
-#include "chrome/browser/history/select_favicon_frames.h"
#include "components/favicon_base/favicon_types.h"
+#include "components/favicon_base/select_favicon_frames.h"
#include "skia/ext/image_operations.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkCanvas.h"
diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc
index 6d3b98e..fca0c7a 100644
--- a/chrome/browser/history/history_backend.cc
+++ b/chrome/browser/history/history_backend.cc
@@ -31,7 +31,6 @@
#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/in_memory_history_backend.h"
#include "chrome/browser/history/page_usage_data.h"
-#include "chrome/browser/history/select_favicon_frames.h"
#include "chrome/browser/history/top_sites.h"
#include "chrome/browser/history/typed_url_syncable_service.h"
#include "chrome/browser/history/visit_filter.h"
@@ -39,6 +38,7 @@
#include "chrome/common/importer/imported_favicon_usage.h"
#include "chrome/common/url_constants.h"
#include "components/bookmarks/core/browser/bookmark_service.h"
+#include "components/favicon_base/select_favicon_frames.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
diff --git a/chrome/browser/history/select_favicon_frames_unittest.cc b/chrome/browser/history/select_favicon_frames_unittest.cc
index 6936ece..d6e2fe9 100644
--- a/chrome/browser/history/select_favicon_frames_unittest.cc
+++ b/chrome/browser/history/select_favicon_frames_unittest.cc
@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/history/select_favicon_frames.h"
+#include "components/favicon_base/select_favicon_frames.h"
-#include "ui/base/layout.h"
-#include "ui/gfx/image/image_skia.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
+#include "ui/base/layout.h"
+#include "ui/gfx/image/image_skia.h"
using std::vector;
diff --git a/chrome/browser/ui/views/create_application_shortcut_view.cc b/chrome/browser/ui/views/create_application_shortcut_view.cc
index 338f94b..a856748 100644
--- a/chrome/browser/ui/views/create_application_shortcut_view.cc
+++ b/chrome/browser/ui/views/create_application_shortcut_view.cc
@@ -13,7 +13,6 @@
#include "base/win/windows_version.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/favicon/favicon_util.h"
-#include "chrome/browser/history/select_favicon_frames.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
@@ -23,6 +22,7 @@
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/pref_names.h"
+#include "components/favicon_base/select_favicon_frames.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
diff --git a/chrome/browser/web_applications/update_shortcut_worker_win.cc b/chrome/browser/web_applications/update_shortcut_worker_win.cc
index 1e88f85..5c6f814 100644
--- a/chrome/browser/web_applications/update_shortcut_worker_win.cc
+++ b/chrome/browser/web_applications/update_shortcut_worker_win.cc
@@ -16,10 +16,10 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
-#include "chrome/browser/history/select_favicon_frames.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/browser/web_applications/web_app_win.h"
+#include "components/favicon_base/select_favicon_frames.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 8485dfb..038c58b 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -828,8 +828,6 @@
'browser/history/page_usage_data.h',
'browser/history/scored_history_match.cc',
'browser/history/scored_history_match.h',
- 'browser/history/select_favicon_frames.cc',
- 'browser/history/select_favicon_frames.h',
'browser/history/shortcuts_database.cc',
'browser/history/shortcuts_database.h',
'browser/history/thumbnail_database.cc',
diff --git a/components/favicon_base.gypi b/components/favicon_base.gypi
index 105b356..a46b289 100644
--- a/components/favicon_base.gypi
+++ b/components/favicon_base.gypi
@@ -9,12 +9,15 @@
'type': 'static_library',
'dependencies': [
'../base/base.gyp:base',
+ '../skia/skia.gyp:skia',
'../ui/gfx/gfx.gyp:gfx',
'../url/url.gyp:url_lib',
],
'sources': [
'favicon_base/favicon_types.cc',
'favicon_base/favicon_types.h',
+ 'favicon_base/select_favicon_frames.cc',
+ 'favicon_base/select_favicon_frames.h',
],
'include_dirs': [
'..',
diff --git a/components/favicon_base/DEPS b/components/favicon_base/DEPS
index b273ae3..20ad28e 100644
--- a/components/favicon_base/DEPS
+++ b/components/favicon_base/DEPS
@@ -1,3 +1,6 @@
include_rules = [
+ "+skia/ext",
+ "+third_party/skia/include",
+ "+ui/base",
"+ui/gfx",
]
diff --git a/chrome/browser/history/select_favicon_frames.cc b/components/favicon_base/select_favicon_frames.cc
index ef7ac79..32f7094 100644
--- a/chrome/browser/history/select_favicon_frames.cc
+++ b/components/favicon_base/select_favicon_frames.cc
@@ -1,9 +1,10 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 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 "chrome/browser/history/select_favicon_frames.h"
+#include "components/favicon_base/select_favicon_frames.h"
+#include <limits>
#include <set>
#include "skia/ext/image_operations.h"
@@ -29,8 +30,7 @@ size_t BiggestCandidate(const std::vector<gfx::Size>& candidate_sizes) {
SkBitmap SampleNearestNeighbor(const SkBitmap& contents, int desired_size) {
SkBitmap bitmap;
- bitmap.setConfig(
- SkBitmap::kARGB_8888_Config, desired_size, desired_size);
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, desired_size, desired_size);
bitmap.allocPixels();
if (!contents.isOpaque())
bitmap.eraseARGB(0, 0, 0, 0);
@@ -44,11 +44,7 @@ SkBitmap SampleNearestNeighbor(const SkBitmap& contents, int desired_size) {
return bitmap;
}
-enum ResizeMethod {
-NONE,
-SAMPLE_NEAREST_NEIGHBOUR,
-LANCZOS
-};
+enum ResizeMethod { NONE, SAMPLE_NEAREST_NEIGHBOUR, LANCZOS };
size_t GetCandidateIndexWithBestScore(
const std::vector<gfx::Size>& candidate_sizes_in_pixel,
@@ -81,26 +77,29 @@ size_t GetCandidateIndexWithBestScore(
// 1) Bitmaps with width and height smaller than |kHugeEdgeSizeInPixel|.
// 2) Bitmaps which need to be scaled down instead of up.
// 3) Bitmaps which do not need to be scaled as much.
- int candidate_index = -1;
+ size_t candidate_index = std::numeric_limits<size_t>::max();
float candidate_score = 0;
for (size_t i = 0; i < candidate_sizes_in_pixel.size(); ++i) {
float average_edge_in_pixel = (candidate_sizes_in_pixel[i].width() +
- candidate_sizes_in_pixel[i].height()) / 2.0f;
+ candidate_sizes_in_pixel[i].height()) /
+ 2.0f;
float score = 0;
if (candidate_sizes_in_pixel[i].width() >= kHugeEdgeSizeInPixel ||
candidate_sizes_in_pixel[i].height() >= kHugeEdgeSizeInPixel) {
- score = std::min(1.0f, desired_size_in_pixel / average_edge_in_pixel) *
- 0.01f;
+ score =
+ std::min(1.0f, desired_size_in_pixel / average_edge_in_pixel) * 0.01f;
} else if (candidate_sizes_in_pixel[i].width() >= desired_size_in_pixel &&
candidate_sizes_in_pixel[i].height() >= desired_size_in_pixel) {
score = desired_size_in_pixel / average_edge_in_pixel * 0.01f + 0.15f;
} else {
score = std::min(1.0f, average_edge_in_pixel / desired_size_in_pixel) *
- 0.01f + 0.1f;
+ 0.01f +
+ 0.1f;
}
- if (candidate_index == -1 || score > candidate_score) {
+ if (candidate_index == std::numeric_limits<size_t>::max() ||
+ score > candidate_score) {
candidate_index = i;
candidate_score = score;
}
@@ -166,7 +165,10 @@ void GetCandidateIndicesWithBestScores(
SelectionResult result;
result.scale_factor = scale_factors[i];
result.index = GetCandidateIndexWithBestScore(candidate_sizes,
- result.scale_factor, desired_size, &score, &result.resize_method);
+ result.scale_factor,
+ desired_size,
+ &score,
+ &result.resize_method);
results->push_back(result);
total_score += score;
}
@@ -181,8 +183,8 @@ SkBitmap GetResizedBitmap(const SkBitmap& source_bitmap,
ui::ScaleFactor scale_factor,
ResizeMethod resize_method) {
float scale = ui::GetImageScale(scale_factor);
- int desired_size_in_pixel = static_cast<int>(
- desired_size_in_dip * scale + 0.5f);
+ int desired_size_in_pixel =
+ static_cast<int>(desired_size_in_dip * scale + 0.5f);
switch (resize_method) {
case NONE:
@@ -191,8 +193,10 @@ SkBitmap GetResizedBitmap(const SkBitmap& source_bitmap,
return SampleNearestNeighbor(source_bitmap, desired_size_in_pixel);
case LANCZOS:
return skia::ImageOperations::Resize(
- source_bitmap, skia::ImageOperations::RESIZE_LANCZOS3,
- desired_size_in_pixel, desired_size_in_pixel);
+ source_bitmap,
+ skia::ImageOperations::RESIZE_LANCZOS3,
+ desired_size_in_pixel,
+ desired_size_in_pixel);
}
return source_bitmap;
}
@@ -208,17 +212,18 @@ gfx::ImageSkia SelectFaviconFrames(
int desired_size,
float* match_score) {
std::vector<SelectionResult> results;
- GetCandidateIndicesWithBestScores(original_sizes, scale_factors,
- desired_size, match_score, &results);
+ GetCandidateIndicesWithBestScores(
+ original_sizes, scale_factors, desired_size, match_score, &results);
gfx::ImageSkia multi_image;
for (size_t i = 0; i < results.size(); ++i) {
const SelectionResult& result = results[i];
SkBitmap resized_bitmap = GetResizedBitmap(bitmaps[result.index],
- desired_size, result.scale_factor, result.resize_method);
- multi_image.AddRepresentation(
- gfx::ImageSkiaRep(resized_bitmap,
- ui::GetImageScale(result.scale_factor)));
+ desired_size,
+ result.scale_factor,
+ result.resize_method);
+ multi_image.AddRepresentation(gfx::ImageSkiaRep(
+ resized_bitmap, ui::GetImageScale(result.scale_factor)));
}
return multi_image;
}
@@ -230,8 +235,8 @@ void SelectFaviconFrameIndices(
std::vector<size_t>* best_indices,
float* match_score) {
std::vector<SelectionResult> results;
- GetCandidateIndicesWithBestScores(frame_pixel_sizes, scale_factors,
- desired_size, match_score, &results);
+ GetCandidateIndicesWithBestScores(
+ frame_pixel_sizes, scale_factors, desired_size, match_score, &results);
std::set<size_t> already_added;
for (size_t i = 0; i < results.size(); ++i) {
diff --git a/chrome/browser/history/select_favicon_frames.h b/components/favicon_base/select_favicon_frames.h
index 9a11656..cc57a80 100644
--- a/chrome/browser/history/select_favicon_frames.h
+++ b/components/favicon_base/select_favicon_frames.h
@@ -1,9 +1,9 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2014 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.
-#ifndef CHROME_BROWSER_HISTORY_SELECT_FAVICON_FRAMES_H_
-#define CHROME_BROWSER_HISTORY_SELECT_FAVICON_FRAMES_H_
+#ifndef COMPONENTS_FAVICON_BASE_SELECT_FAVICON_FRAMES_H_
+#define COMPONENTS_FAVICON_BASE_SELECT_FAVICON_FRAMES_H_
#include <vector>
@@ -59,4 +59,4 @@ void SelectFaviconFrameIndices(
std::vector<size_t>* best_indices,
float* score);
-#endif // CHROME_BROWSER_HISTORY_SELECT_FAVICON_FRAMES_H_
+#endif // COMPONENTS_FAVICON_BASE_SELECT_FAVICON_FRAMES_H_