OLD | NEW |
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/thumbnails/thumbnail_tab_helper.h" | 5 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/history/top_sites.h" | 9 #include "chrome/browser/history/top_sites.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/thumbnails/render_widget_snapshot_taker.h" | 11 #include "chrome/browser/thumbnails/render_widget_snapshot_taker.h" |
12 #include "content/public/browser/notification_details.h" | 12 #include "content/public/browser/notification_details.h" |
13 #include "content/public/browser/notification_source.h" | 13 #include "content/public/browser/notification_source.h" |
14 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
15 #include "content/public/browser/render_view_host.h" | 15 #include "content/public/browser/render_view_host.h" |
16 #include "content/public/browser/render_widget_host_view.h" | 16 #include "content/public/browser/render_widget_host_view.h" |
17 #include "skia/ext/platform_canvas.h" | 17 #include "skia/ext/platform_canvas.h" |
18 #include "ui/gfx/color_utils.h" | 18 #include "ui/gfx/color_utils.h" |
| 19 #include "ui/gfx/size_conversions.h" |
19 #include "ui/gfx/screen.h" | 20 #include "ui/gfx/screen.h" |
20 #include "ui/gfx/scrollbar_size.h" | 21 #include "ui/gfx/scrollbar_size.h" |
21 #include "ui/gfx/skbitmap_operations.h" | 22 #include "ui/gfx/skbitmap_operations.h" |
22 | 23 |
23 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
24 #include "base/win/windows_version.h" | 25 #include "base/win/windows_version.h" |
25 #endif | 26 #endif |
26 | 27 |
27 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ThumbnailTabHelper) | 28 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ThumbnailTabHelper) |
28 | 29 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 // ui::SCALE_FACTOR_200P because the high resolution thumbnail on high density | 80 // ui::SCALE_FACTOR_200P because the high resolution thumbnail on high density |
80 // display alleviates the aliasing. | 81 // display alleviates the aliasing. |
81 // TODO(mazda): Copy the pixels with the smaller size in the case of | 82 // TODO(mazda): Copy the pixels with the smaller size in the case of |
82 // ui::SCALE_FACTOR_100P once the resampling method has been improved. | 83 // ui::SCALE_FACTOR_100P once the resampling method has been improved. |
83 gfx::Size GetCopySizeForThumbnail(content::RenderWidgetHostView* view) { | 84 gfx::Size GetCopySizeForThumbnail(content::RenderWidgetHostView* view) { |
84 gfx::Size copy_size(kThumbnailWidth, kThumbnailHeight); | 85 gfx::Size copy_size(kThumbnailWidth, kThumbnailHeight); |
85 ui::ScaleFactor scale_factor = | 86 ui::ScaleFactor scale_factor = |
86 ui::GetScaleFactorForNativeView(view->GetNativeView()); | 87 ui::GetScaleFactorForNativeView(view->GetNativeView()); |
87 switch (scale_factor) { | 88 switch (scale_factor) { |
88 case ui::SCALE_FACTOR_100P: | 89 case ui::SCALE_FACTOR_100P: |
89 copy_size = | 90 copy_size = gfx::ToFlooredSize( |
90 copy_size.Scale(ui::GetScaleFactorScale(ui::SCALE_FACTOR_200P)); | 91 copy_size.Scale(ui::GetScaleFactorScale(ui::SCALE_FACTOR_200P))); |
91 break; | 92 break; |
92 case ui::SCALE_FACTOR_200P: | 93 case ui::SCALE_FACTOR_200P: |
93 // Use the size as-is. | 94 // Use the size as-is. |
94 break; | 95 break; |
95 default: | 96 default: |
96 DLOG(WARNING) << "Unsupported scale factor. Use the same copy size as " | 97 DLOG(WARNING) << "Unsupported scale factor. Use the same copy size as " |
97 << "ui::SCALE_FACTOR_100P"; | 98 << "ui::SCALE_FACTOR_100P"; |
98 copy_size = | 99 copy_size = gfx::ToFlooredSize( |
99 copy_size.Scale(ui::GetScaleFactorScale(ui::SCALE_FACTOR_200P)); | 100 copy_size.Scale(ui::GetScaleFactorScale(ui::SCALE_FACTOR_200P))); |
100 break; | 101 break; |
101 } | 102 } |
102 return copy_size; | 103 return copy_size; |
103 } | 104 } |
104 | 105 |
105 // Returns the size of the thumbnail stored in the database in pixel. | 106 // Returns the size of the thumbnail stored in the database in pixel. |
106 gfx::Size GetThumbnailSizeInPixel() { | 107 gfx::Size GetThumbnailSizeInPixel() { |
107 gfx::Size thumbnail_size(kThumbnailWidth, kThumbnailHeight); | 108 gfx::Size thumbnail_size(kThumbnailWidth, kThumbnailHeight); |
108 // Determine the resolution of the thumbnail based on the primary monitor. | 109 // Determine the resolution of the thumbnail based on the primary monitor. |
109 // TODO(oshima): Use device's default scale factor. | 110 // TODO(oshima): Use device's default scale factor. |
110 gfx::Display primary_display = gfx::Screen::GetPrimaryDisplay(); | 111 gfx::Display primary_display = gfx::Screen::GetPrimaryDisplay(); |
111 return thumbnail_size.Scale(primary_display.device_scale_factor()); | 112 return gfx::ToFlooredSize( |
| 113 thumbnail_size.Scale(primary_display.device_scale_factor())); |
112 } | 114 } |
113 | 115 |
114 // Returns the clipping rectangle that is used for creating a thumbnail with | 116 // Returns the clipping rectangle that is used for creating a thumbnail with |
115 // the size of |desired_size| from the bitmap with the size of |source_size|. | 117 // the size of |desired_size| from the bitmap with the size of |source_size|. |
116 // The type of clipping that needs to be done is assigned to |clip_result|. | 118 // The type of clipping that needs to be done is assigned to |clip_result|. |
117 gfx::Rect GetClippingRect(const gfx::Size& source_size, | 119 gfx::Rect GetClippingRect(const gfx::Size& source_size, |
118 const gfx::Size& desired_size, | 120 const gfx::Size& desired_size, |
119 ThumbnailTabHelper::ClipResult* clip_result) { | 121 ThumbnailTabHelper::ClipResult* clip_result) { |
120 DCHECK(clip_result); | 122 DCHECK(clip_result); |
121 | 123 |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 void ThumbnailTabHelper::DidStartLoading( | 477 void ThumbnailTabHelper::DidStartLoading( |
476 content::RenderViewHost* render_view_host) { | 478 content::RenderViewHost* render_view_host) { |
477 load_interrupted_ = false; | 479 load_interrupted_ = false; |
478 } | 480 } |
479 | 481 |
480 void ThumbnailTabHelper::StopNavigation() { | 482 void ThumbnailTabHelper::StopNavigation() { |
481 // This function gets called when the page loading is interrupted by the | 483 // This function gets called when the page loading is interrupted by the |
482 // stop button. | 484 // stop button. |
483 load_interrupted_ = true; | 485 load_interrupted_ = true; |
484 } | 486 } |
OLD | NEW |