OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/touch/tabs/touch_tab.h" | 5 #include "chrome/browser/ui/touch/tabs/touch_tab.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/themes/theme_service.h" | 8 #include "chrome/browser/themes/theme_service.h" |
9 #include "grit/app_resources.h" | 9 #include "grit/app_resources.h" |
10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
11 #include "grit/theme_resources_standard.h" | 11 #include "grit/theme_resources_standard.h" |
12 #include "skia/ext/image_operations.h" | |
12 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/gfx/canvas_skia.h" | 14 #include "ui/gfx/canvas_skia.h" |
14 #include "ui/gfx/favicon_size.h" | 15 #include "ui/gfx/favicon_size.h" |
15 #include "ui/gfx/path.h" | 16 #include "ui/gfx/path.h" |
16 #include "ui/gfx/skbitmap_operations.h" | 17 #include "ui/gfx/skbitmap_operations.h" |
17 | 18 |
18 static const int kLeftPadding = 16; | 19 static const int kLeftPadding = 16; |
19 static const int kRightPadding = 15; | 20 static const int kRightPadding = 15; |
20 static const int kDropShadowHeight = 2; | 21 static const int kDropShadowHeight = 2; |
21 | 22 |
22 // The size of the favicon touch area. This generally would be the same as | 23 // The size of the favicon touch area. This is not the same as kFaviconSize |
23 // kFaviconSize in ui/gfx/favicon_size.h | 24 // which is defined in ui/gfx/favicon_size.h. |
24 static const int kTouchTabIconSize = 32; | 25 static const int kTouchTargetIconSize = 32; |
25 | 26 |
26 TouchTab::TouchTabImage TouchTab::tab_alpha = {0}; | 27 TouchTab::TouchTabImage TouchTab::tab_alpha = {0}; |
27 TouchTab::TouchTabImage TouchTab::tab_active = {0}; | 28 TouchTab::TouchTabImage TouchTab::tab_active = {0}; |
28 TouchTab::TouchTabImage TouchTab::tab_inactive = {0}; | 29 TouchTab::TouchTabImage TouchTab::tab_inactive = {0}; |
29 | 30 |
31 // static | |
32 void calc_touch_icon_target_size(int* width, int* height) { | |
sky
2011/06/09 16:53:00
This should really be static.
Emmanuel Saint-loubert-Bié
2011/06/10 02:21:45
Yes of course, sorry for this cut and paste error
| |
33 if (*width > kTouchTargetIconSize || *height > kTouchTargetIconSize) { | |
34 // Too big, resize it maintaining the aspect ratio. | |
35 float aspect_ratio = static_cast<float>(*width) / | |
36 static_cast<float>(*height); | |
37 *height = kTouchTargetIconSize; | |
38 *width = static_cast<int>(aspect_ratio * *height); | |
39 if (*width > kTouchTargetIconSize) { | |
40 *width = kTouchTargetIconSize; | |
41 *height = static_cast<int>(*width / aspect_ratio); | |
42 } | |
43 } | |
44 } | |
45 | |
30 //////////////////////////////////////////////////////////////////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// |
31 // TouchTab, public: | 47 // TouchTab, public: |
32 | 48 |
33 TouchTab::TouchTab(TabController* controller) | 49 TouchTab::TouchTab(TabController* controller) |
34 : BaseTab(controller) { | 50 : BaseTab(controller) { |
35 InitTabResources(); | 51 InitTabResources(); |
36 } | 52 } |
37 | 53 |
38 TouchTab::~TouchTab() { | 54 TouchTab::~TouchTab() { |
39 } | 55 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 | 189 |
174 // Now draw the highlights/shadows around the tab edge. | 190 // Now draw the highlights/shadows around the tab edge. |
175 canvas->DrawBitmapInt(*tab_image->image_l, 0, y_base); | 191 canvas->DrawBitmapInt(*tab_image->image_l, 0, y_base); |
176 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, y_base, | 192 canvas->TileImageInt(*tab_image->image_c, tab_image->l_width, y_base, |
177 width() - tab_image->l_width - tab_image->r_width, image_height); | 193 width() - tab_image->l_width - tab_image->r_width, image_height); |
178 canvas->DrawBitmapInt(*tab_image->image_r, width() - tab_image->r_width, | 194 canvas->DrawBitmapInt(*tab_image->image_r, width() - tab_image->r_width, |
179 y_base); | 195 y_base); |
180 } | 196 } |
181 | 197 |
182 void TouchTab::PaintIcon(gfx::Canvas* canvas) { | 198 void TouchTab::PaintIcon(gfx::Canvas* canvas) { |
183 // TODO(wyck): use thumbnailer to get better page images | |
184 int x = favicon_bounds_.x(); | 199 int x = favicon_bounds_.x(); |
185 int y = favicon_bounds_.y(); | 200 int y = favicon_bounds_.y(); |
186 | 201 |
187 TouchTabImage* tab_image = &tab_active; | 202 TouchTabImage* tab_image = &tab_active; |
188 int x_base = tab_image->image_l->width(); | 203 int x_base = tab_image->image_l->width(); |
189 | 204 |
190 x += x_base; | 205 x += x_base; |
191 | 206 |
192 if (base::i18n::IsRTL()) { | 207 if (base::i18n::IsRTL()) { |
193 x = width() - x - | 208 x = width() - x - (data().favicon.isNull() |
194 (data().favicon.isNull() ? kFaviconSize : data().favicon.width()); | 209 ? kFaviconSize : data().favicon.width()); |
sky
2011/06/09 16:53:00
Shouldn't this be kTouchTargetIconSize always?
Emmanuel Saint-loubert-Bié
2011/06/10 02:21:45
Yes good catch, and it will matter even more now t
| |
195 } | 210 } |
196 | 211 |
197 int favicon_x = x; | 212 int favicon_x = x; |
sky
2011/06/09 16:53:00
I don't think 212-214 are needed.
Emmanuel Saint-loubert-Bié
2011/06/10 02:21:45
Indeed, seems like old cruft
| |
198 if (!data().favicon.isNull() && data().favicon.width() != kFaviconSize) | 213 if (!data().favicon.isNull() && data().favicon.width() != kFaviconSize) |
199 favicon_x += (data().favicon.width() - kFaviconSize) / 2; | 214 favicon_x += (data().favicon.width() - kFaviconSize) / 2; |
200 | 215 |
201 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { | 216 if (data().network_state != TabRendererData::NETWORK_STATE_NONE) { |
202 ui::ThemeProvider* tp = GetThemeProvider(); | 217 ui::ThemeProvider* tp = GetThemeProvider(); |
203 SkBitmap frames(*tp->GetBitmapNamed( | 218 SkBitmap frames( |
204 (data().network_state == TabRendererData::NETWORK_STATE_WAITING) ? | 219 *tp->GetBitmapNamed( |
205 IDR_THROBBER_WAITING : IDR_THROBBER)); | 220 (data().network_state == TabRendererData::NETWORK_STATE_WAITING) |
221 ? IDR_THROBBER_WAITING : IDR_THROBBER)); | |
206 int image_size = frames.height(); | 222 int image_size = frames.height(); |
207 int image_offset = loading_animation_frame() * image_size; | 223 int image_offset = loading_animation_frame() * image_size; |
208 canvas->DrawBitmapInt(frames, image_offset, 0, image_size, image_size, x, y, | 224 canvas->DrawBitmapInt(frames, image_offset, 0, image_size, image_size, x, |
209 kTouchTabIconSize, kTouchTabIconSize, false); | 225 y, kTouchTargetIconSize, kTouchTargetIconSize, false); |
sky
2011/06/09 16:53:00
Is the throbber size 32x32 so that it lines up nic
Emmanuel Saint-loubert-Bié
2011/06/10 02:21:45
Yes it has been 32x32 for a while. No change neede
| |
210 } else { | 226 } else { |
211 canvas->Save(); | 227 canvas->Save(); |
212 canvas->ClipRectInt(0, 0, width(), height()); | 228 canvas->ClipRectInt(0, 0, width(), height()); |
213 if (should_display_crashed_favicon()) { | 229 if (should_display_crashed_favicon()) { |
214 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 230 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
215 SkBitmap crashed_favicon(*rb.GetBitmapNamed(IDR_SAD_FAVICON)); | 231 SkBitmap crashed_favicon(*rb.GetBitmapNamed(IDR_SAD_FAVICON)); |
Emmanuel Saint-loubert-Bié
2011/06/10 02:21:45
On the other hand the IDR_SAD_FAVICON is not 32x32
| |
216 canvas->DrawBitmapInt(crashed_favicon, 0, 0, crashed_favicon.width(), | 232 canvas->DrawBitmapInt(crashed_favicon, 0, 0, crashed_favicon.width(), |
217 crashed_favicon.height(), x, y + favicon_hiding_offset(), | 233 crashed_favicon.height(), x, y + favicon_hiding_offset(), |
218 kTouchTabIconSize, kTouchTabIconSize, true); | 234 kTouchTargetIconSize, kTouchTargetIconSize, true); |
219 } else { | 235 } else { |
220 if (!data().favicon.isNull()) { | 236 if (!data().favicon.isNull()) { |
221 | 237 int width = data().favicon.width(); |
222 if ((data().favicon.width() == kTouchTabIconSize) && | 238 int height = data().favicon.height(); |
223 (data().favicon.height() == kTouchTabIconSize)) { | 239 if (width != kTouchTargetIconSize || height != kTouchTargetIconSize) { |
224 canvas->DrawBitmapInt(data().favicon, 0, 0, | 240 calc_touch_icon_target_size(&width, &height); |
225 data().favicon.width(), data().favicon.height(), | 241 SkBitmap scaled_image = skia::ImageOperations::Resize(data().favicon, |
sky
2011/06/09 16:53:00
Seems painful to resize the image each time throug
Emmanuel Saint-loubert-Bié
2011/06/10 02:21:45
That is a great point. We did not cache before, bu
| |
226 x, y + favicon_hiding_offset(), | 242 skia::ImageOperations::RESIZE_BEST, width, height); |
227 kTouchTabIconSize, kTouchTabIconSize, true); | 243 canvas->DrawBitmapInt(scaled_image, 0, 0, scaled_image.width(), |
sky
2011/06/09 16:53:00
If the favicon width is not the same as the height
Emmanuel Saint-loubert-Bié
2011/06/10 02:21:45
Done.
| |
244 scaled_image.height(), x, y + favicon_hiding_offset(), | |
245 kTouchTargetIconSize, kTouchTargetIconSize, true); | |
228 } else { | 246 } else { |
229 // Draw a background around target touch area in case the favicon | |
230 // is smaller than touch area (e.g www.google.com is 16x16 now) | |
231 canvas->DrawRectInt( | |
232 GetThemeProvider()->GetColor( | |
233 ThemeService::COLOR_BUTTON_BACKGROUND), | |
234 x, y, kTouchTabIconSize, kTouchTabIconSize); | |
235 | |
236 // We center the image | |
237 // TODO(saintlou): later request larger image from HistoryService | |
238 canvas->DrawBitmapInt(data().favicon, 0, 0, data().favicon.width(), | 247 canvas->DrawBitmapInt(data().favicon, 0, 0, data().favicon.width(), |
239 data().favicon.height(), | 248 data().favicon.height(), x, y + favicon_hiding_offset(), |
240 x + ((kTouchTabIconSize - data().favicon.width()) / 2), | 249 kTouchTargetIconSize, kTouchTargetIconSize, true); |
241 y + ((kTouchTabIconSize - data().favicon.height()) / 2) + | |
242 favicon_hiding_offset(), | |
243 data().favicon.width(), data().favicon.height(), true); | |
244 } | 250 } |
245 } | 251 } |
246 } | 252 } |
247 canvas->Restore(); | 253 canvas->Restore(); |
248 } | 254 } |
249 } | 255 } |
250 | 256 |
251 // static | 257 // static |
252 void TouchTab::InitTabResources() { | 258 void TouchTab::InitTabResources() { |
253 static bool initialized = false; | 259 static bool initialized = false; |
(...skipping 20 matching lines...) Expand all Loading... | |
274 tab_active.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT); | 280 tab_active.image_r = rb.GetBitmapNamed(IDR_TAB_ACTIVE_RIGHT); |
275 tab_active.l_width = tab_active.image_l->width(); | 281 tab_active.l_width = tab_active.image_l->width(); |
276 tab_active.r_width = tab_active.image_r->width(); | 282 tab_active.r_width = tab_active.image_r->width(); |
277 | 283 |
278 tab_inactive.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); | 284 tab_inactive.image_l = rb.GetBitmapNamed(IDR_TAB_INACTIVE_LEFT); |
279 tab_inactive.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); | 285 tab_inactive.image_c = rb.GetBitmapNamed(IDR_TAB_INACTIVE_CENTER); |
280 tab_inactive.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); | 286 tab_inactive.image_r = rb.GetBitmapNamed(IDR_TAB_INACTIVE_RIGHT); |
281 tab_inactive.l_width = tab_inactive.image_l->width(); | 287 tab_inactive.l_width = tab_inactive.image_l->width(); |
282 tab_inactive.r_width = tab_inactive.image_r->width(); | 288 tab_inactive.r_width = tab_inactive.image_r->width(); |
283 } | 289 } |
OLD | NEW |