Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: chrome/browser/themes/browser_theme_pack.cc

Issue 18486007: Fix the misalignment on CrOS of the tab background images (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes as per sky@ Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/themes/browser_theme_pack.h" 5 #include "chrome/browser/themes/browser_theme_pack.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/memory/ref_counted_memory.h" 9 #include "base/memory/ref_counted_memory.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 25 matching lines...) Expand all
36 #include "ui/gfx/skia_util.h" 36 #include "ui/gfx/skia_util.h"
37 37
38 using content::BrowserThread; 38 using content::BrowserThread;
39 using extensions::Extension; 39 using extensions::Extension;
40 40
41 namespace { 41 namespace {
42 42
43 // Version number of the current theme pack. We just throw out and rebuild 43 // Version number of the current theme pack. We just throw out and rebuild
44 // theme packs that aren't int-equal to this. Increment this number if you 44 // theme packs that aren't int-equal to this. Increment this number if you
45 // change default theme assets. 45 // change default theme assets.
46 const int kThemePackVersion = 31; 46 const int kThemePackVersion = 32;
47 47
48 // IDs that are in the DataPack won't clash with the positive integer 48 // IDs that are in the DataPack won't clash with the positive integer
49 // uint16. kHeaderID should always have the maximum value because we want the 49 // uint16. kHeaderID should always have the maximum value because we want the
50 // "header" to be written last. That way we can detect whether the pack was 50 // "header" to be written last. That way we can detect whether the pack was
51 // successfully written and ignore and regenerate if it was only partially 51 // successfully written and ignore and regenerate if it was only partially
52 // written (i.e. chrome crashed on a different thread while writing the pack). 52 // written (i.e. chrome crashed on a different thread while writing the pack).
53 const int kMaxID = 0x0000FFFF; // Max unsigned 16-bit int. 53 const int kMaxID = 0x0000FFFF; // Max unsigned 16-bit int.
54 const int kHeaderID = kMaxID - 1; 54 const int kHeaderID = kMaxID - 1;
55 const int kTintsID = kMaxID - 2; 55 const int kTintsID = kMaxID - 2;
56 const int kColorsID = kMaxID - 3; 56 const int kColorsID = kMaxID - 3;
57 const int kDisplayPropertiesID = kMaxID - 4; 57 const int kDisplayPropertiesID = kMaxID - 4;
58 const int kSourceImagesID = kMaxID - 5; 58 const int kSourceImagesID = kMaxID - 5;
59 const int kScaleFactorsID = kMaxID - 6; 59 const int kScaleFactorsID = kMaxID - 6;
60 60
61 // The sum of kFrameBorderThickness and kNonClientRestoredExtraThickness from
62 // OpaqueBrowserFrameView.
63 const int kRestoredTabVerticalOffset = 15;
64
65 // Persistent constants for the main images that we need. These have the same 61 // Persistent constants for the main images that we need. These have the same
66 // names as their IDR_* counterparts but these values will always stay the 62 // names as their IDR_* counterparts but these values will always stay the
67 // same. 63 // same.
68 const int PRS_THEME_FRAME = 1; 64 const int PRS_THEME_FRAME = 1;
69 const int PRS_THEME_FRAME_INACTIVE = 2; 65 const int PRS_THEME_FRAME_INACTIVE = 2;
70 const int PRS_THEME_FRAME_INCOGNITO = 3; 66 const int PRS_THEME_FRAME_INCOGNITO = 3;
71 const int PRS_THEME_FRAME_INCOGNITO_INACTIVE = 4; 67 const int PRS_THEME_FRAME_INCOGNITO_INACTIVE = 4;
72 const int PRS_THEME_TOOLBAR = 5; 68 const int PRS_THEME_TOOLBAR = 5;
73 const int PRS_THEME_TAB_BACKGROUND = 6; 69 const int PRS_THEME_TAB_BACKGROUND_OVERLAY = 6;
74 const int PRS_THEME_TAB_BACKGROUND_INCOGNITO = 7; 70 const int PRS_THEME_TAB_BACKGROUND_INCOGNITO_OVERLAY = 7;
75 const int PRS_THEME_TAB_BACKGROUND_V = 8; 71 const int PRS_THEME_TAB_BACKGROUND_V_OVERLAY = 8;
76 const int PRS_THEME_NTP_BACKGROUND = 9; 72 const int PRS_THEME_NTP_BACKGROUND = 9;
77 const int PRS_THEME_FRAME_OVERLAY = 10; 73 const int PRS_THEME_FRAME_OVERLAY = 10;
78 const int PRS_THEME_FRAME_OVERLAY_INACTIVE = 11; 74 const int PRS_THEME_FRAME_OVERLAY_INACTIVE = 11;
79 const int PRS_THEME_BUTTON_BACKGROUND = 12; 75 const int PRS_THEME_BUTTON_BACKGROUND = 12;
80 const int PRS_THEME_NTP_ATTRIBUTION = 13; 76 const int PRS_THEME_NTP_ATTRIBUTION = 13;
81 const int PRS_THEME_WINDOW_CONTROL_BACKGROUND = 14; 77 const int PRS_THEME_WINDOW_CONTROL_BACKGROUND = 14;
78 const int PRS_THEME_TAB_BACKGROUND = 15;
79 const int PRS_THEME_TAB_BACKGROUND_INCOGNITO = 16;
82 80
83 struct PersistingImagesTable { 81 struct PersistingImagesTable {
84 // A non-changing integer ID meant to be saved in theme packs. This ID must 82 // A non-changing integer ID meant to be saved in theme packs. This ID must
85 // not change between versions of chrome. 83 // not change between versions of chrome.
86 int persistent_id; 84 int persistent_id;
87 85
88 // The IDR that depends on the whims of GRIT and therefore changes whenever 86 // The IDR that depends on the whims of GRIT and therefore changes whenever
89 // someone adds a new resource. 87 // someone adds a new resource.
90 int idr_id; 88 int idr_id;
91 89
92 // String to check for when parsing theme manifests or NULL if this isn't 90 // String to check for when parsing theme manifests or NULL if this isn't
93 // supposed to be changeable by the user. 91 // supposed to be changeable by the user.
94 const char* key; 92 const char* key;
95 }; 93 };
96 94
97 // IDR_* resource names change whenever new resources are added; use persistent 95 // IDR_* resource names change whenever new resources are added; use persistent
98 // IDs when storing to a cached pack. 96 // IDs when storing to a cached pack.
99 PersistingImagesTable kPersistingImages[] = { 97 PersistingImagesTable kPersistingImages[] = {
100 { PRS_THEME_FRAME, IDR_THEME_FRAME, 98 { PRS_THEME_FRAME, IDR_THEME_FRAME,
101 "theme_frame" }, 99 "theme_frame" },
102 { PRS_THEME_FRAME_INACTIVE, IDR_THEME_FRAME_INACTIVE, 100 { PRS_THEME_FRAME_INACTIVE, IDR_THEME_FRAME_INACTIVE,
103 "theme_frame_inactive" }, 101 "theme_frame_inactive" },
104 { PRS_THEME_FRAME_INCOGNITO, IDR_THEME_FRAME_INCOGNITO, 102 { PRS_THEME_FRAME_INCOGNITO, IDR_THEME_FRAME_INCOGNITO,
105 "theme_frame_incognito" }, 103 "theme_frame_incognito" },
106 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, IDR_THEME_FRAME_INCOGNITO_INACTIVE, 104 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, IDR_THEME_FRAME_INCOGNITO_INACTIVE,
107 "theme_frame_incognito_inactive" }, 105 "theme_frame_incognito_inactive" },
108 { PRS_THEME_TOOLBAR, IDR_THEME_TOOLBAR, 106 { PRS_THEME_TOOLBAR, IDR_THEME_TOOLBAR,
109 "theme_toolbar" }, 107 "theme_toolbar" },
110 { PRS_THEME_TAB_BACKGROUND, IDR_THEME_TAB_BACKGROUND, 108 { PRS_THEME_TAB_BACKGROUND_OVERLAY, IDR_THEME_TAB_BACKGROUND_OVERLAY,
111 "theme_tab_background" }, 109 "theme_tab_background" },
112 { PRS_THEME_TAB_BACKGROUND_INCOGNITO, IDR_THEME_TAB_BACKGROUND_INCOGNITO, 110 { PRS_THEME_TAB_BACKGROUND_INCOGNITO_OVERLAY,
111 IDR_THEME_TAB_BACKGROUND_INCOGNITO_OVERLAY,
113 "theme_tab_background_incognito" }, 112 "theme_tab_background_incognito" },
114 { PRS_THEME_TAB_BACKGROUND_V, IDR_THEME_TAB_BACKGROUND_V, 113 { PRS_THEME_TAB_BACKGROUND_V_OVERLAY, IDR_THEME_TAB_BACKGROUND_V_OVERLAY,
115 "theme_tab_background_v"}, 114 "theme_tab_background_v"},
116 { PRS_THEME_NTP_BACKGROUND, IDR_THEME_NTP_BACKGROUND, 115 { PRS_THEME_NTP_BACKGROUND, IDR_THEME_NTP_BACKGROUND,
117 "theme_ntp_background" }, 116 "theme_ntp_background" },
118 { PRS_THEME_FRAME_OVERLAY, IDR_THEME_FRAME_OVERLAY, 117 { PRS_THEME_FRAME_OVERLAY, IDR_THEME_FRAME_OVERLAY,
119 "theme_frame_overlay" }, 118 "theme_frame_overlay" },
120 { PRS_THEME_FRAME_OVERLAY_INACTIVE, IDR_THEME_FRAME_OVERLAY_INACTIVE, 119 { PRS_THEME_FRAME_OVERLAY_INACTIVE, IDR_THEME_FRAME_OVERLAY_INACTIVE,
121 "theme_frame_overlay_inactive" }, 120 "theme_frame_overlay_inactive" },
122 { PRS_THEME_BUTTON_BACKGROUND, IDR_THEME_BUTTON_BACKGROUND, 121 { PRS_THEME_BUTTON_BACKGROUND, IDR_THEME_BUTTON_BACKGROUND,
123 "theme_button_background" }, 122 "theme_button_background" },
124 { PRS_THEME_NTP_ATTRIBUTION, IDR_THEME_NTP_ATTRIBUTION, 123 { PRS_THEME_NTP_ATTRIBUTION, IDR_THEME_NTP_ATTRIBUTION,
125 "theme_ntp_attribution" }, 124 "theme_ntp_attribution" },
126 { PRS_THEME_WINDOW_CONTROL_BACKGROUND, IDR_THEME_WINDOW_CONTROL_BACKGROUND, 125 { PRS_THEME_WINDOW_CONTROL_BACKGROUND, IDR_THEME_WINDOW_CONTROL_BACKGROUND,
127 "theme_window_control_background"}, 126 "theme_window_control_background"},
128 127
129 // The rest of these entries have no key because they can't be overridden 128 // The rest of these entries have no key because they can't be overridden
130 // from the json manifest. 129 // from the json manifest.
131 { 15, IDR_BACK, NULL }, 130 { PRS_THEME_TAB_BACKGROUND, IDR_THEME_TAB_BACKGROUND, NULL },
132 { 16, IDR_BACK_D, NULL }, 131 { PRS_THEME_TAB_BACKGROUND_INCOGNITO,
133 { 17, IDR_BACK_H, NULL }, 132 IDR_THEME_TAB_BACKGROUND_INCOGNITO, NULL },
134 { 18, IDR_BACK_P, NULL }, 133 { 17, IDR_BACK, NULL },
135 { 19, IDR_FORWARD, NULL }, 134 { 18, IDR_BACK_D, NULL },
136 { 20, IDR_FORWARD_D, NULL }, 135 { 19, IDR_BACK_H, NULL },
137 { 21, IDR_FORWARD_H, NULL }, 136 { 20, IDR_BACK_P, NULL },
138 { 22, IDR_FORWARD_P, NULL }, 137 { 21, IDR_FORWARD, NULL },
139 { 23, IDR_HOME, NULL }, 138 { 22, IDR_FORWARD_D, NULL },
140 { 24, IDR_HOME_H, NULL }, 139 { 23, IDR_FORWARD_H, NULL },
141 { 25, IDR_HOME_P, NULL }, 140 { 24, IDR_FORWARD_P, NULL },
142 { 26, IDR_RELOAD, NULL }, 141 { 25, IDR_HOME, NULL },
143 { 27, IDR_RELOAD_H, NULL }, 142 { 26, IDR_HOME_H, NULL },
144 { 28, IDR_RELOAD_P, NULL }, 143 { 27, IDR_HOME_P, NULL },
145 { 29, IDR_STOP, NULL }, 144 { 28, IDR_RELOAD, NULL },
146 { 30, IDR_STOP_D, NULL }, 145 { 29, IDR_RELOAD_H, NULL },
147 { 31, IDR_STOP_H, NULL }, 146 { 30, IDR_RELOAD_P, NULL },
148 { 32, IDR_STOP_P, NULL }, 147 { 31, IDR_STOP, NULL },
149 { 33, IDR_BROWSER_ACTIONS_OVERFLOW, NULL }, 148 { 32, IDR_STOP_D, NULL },
150 { 34, IDR_BROWSER_ACTIONS_OVERFLOW_H, NULL }, 149 { 33, IDR_STOP_H, NULL },
151 { 35, IDR_BROWSER_ACTIONS_OVERFLOW_P, NULL }, 150 { 34, IDR_STOP_P, NULL },
152 { 36, IDR_TOOLS, NULL }, 151 { 35, IDR_BROWSER_ACTIONS_OVERFLOW, NULL },
153 { 37, IDR_TOOLS_H, NULL }, 152 { 36, IDR_BROWSER_ACTIONS_OVERFLOW_H, NULL },
154 { 38, IDR_TOOLS_P, NULL }, 153 { 37, IDR_BROWSER_ACTIONS_OVERFLOW_P, NULL },
155 { 39, IDR_MENU_DROPARROW, NULL }, 154 { 38, IDR_TOOLS, NULL },
156 { 40, IDR_THROBBER, NULL }, 155 { 39, IDR_TOOLS_H, NULL },
157 { 41, IDR_THROBBER_WAITING, NULL }, 156 { 40, IDR_TOOLS_P, NULL },
158 { 42, IDR_THROBBER_LIGHT, NULL }, 157 { 41, IDR_MENU_DROPARROW, NULL },
159 { 43, IDR_TOOLBAR_BEZEL_HOVER, NULL }, 158 { 42, IDR_THROBBER, NULL },
160 { 44, IDR_TOOLBAR_BEZEL_PRESSED, NULL }, 159 { 43, IDR_THROBBER_WAITING, NULL },
161 { 45, IDR_TOOLS_BAR, NULL }, 160 { 44, IDR_THROBBER_LIGHT, NULL },
161 { 45, IDR_TOOLBAR_BEZEL_HOVER, NULL },
162 { 46, IDR_TOOLBAR_BEZEL_PRESSED, NULL },
163 { 47, IDR_TOOLS_BAR, NULL },
162 }; 164 };
163 const size_t kPersistingImagesLength = arraysize(kPersistingImages); 165 const size_t kPersistingImagesLength = arraysize(kPersistingImages);
164 166
165 #if defined(OS_WIN) && defined(USE_AURA) 167 #if defined(OS_WIN) && defined(USE_AURA)
166 // Persistent theme ids for Windows AURA. 168 // Persistent theme ids for Windows AURA.
167 const int PRS_THEME_FRAME_WIN = 100; 169 const int PRS_THEME_FRAME_WIN = 100;
168 const int PRS_THEME_FRAME_INACTIVE_WIN = 101; 170 const int PRS_THEME_FRAME_INACTIVE_WIN = 101;
169 const int PRS_THEME_FRAME_INCOGNITO_WIN = 102; 171 const int PRS_THEME_FRAME_INCOGNITO_WIN = 102;
170 const int PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN = 103; 172 const int PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN = 103;
171 const int PRS_THEME_TOOLBAR_WIN = 104; 173 const int PRS_THEME_TOOLBAR_WIN = 104;
172 const int PRS_THEME_TAB_BACKGROUND_WIN = 105; 174 const int PRS_THEME_TAB_BACKGROUND_OVERLAY_WIN = 105;
173 const int PRS_THEME_TAB_BACKGROUND_INCOGNITO_WIN = 106; 175 const int PRS_THEME_TAB_BACKGROUND_INCOGNITO_OVERLAY_WIN = 106;
176 const int PRS_THEME_TAB_BACKGROUND_WIN = 107;
177 const int PRS_THEME_TAB_BACKGROUND_INCOGNITO_WIN = 108;
174 178
175 // Persistent theme to resource id mapping for Windows AURA. 179 // Persistent theme to resource id mapping for Windows AURA.
176 PersistingImagesTable kPersistingImagesWinDesktopAura[] = { 180 PersistingImagesTable kPersistingImagesWinDesktopAura[] = {
177 { PRS_THEME_FRAME_WIN, IDR_THEME_FRAME_WIN, 181 { PRS_THEME_FRAME_WIN, IDR_THEME_FRAME_WIN,
178 "theme_frame" }, 182 "theme_frame" },
179 { PRS_THEME_FRAME_INACTIVE_WIN, IDR_THEME_FRAME_INACTIVE_WIN, 183 { PRS_THEME_FRAME_INACTIVE_WIN, IDR_THEME_FRAME_INACTIVE_WIN,
180 "theme_frame_inactive" }, 184 "theme_frame_inactive" },
181 { PRS_THEME_FRAME_INCOGNITO_WIN, IDR_THEME_FRAME_INCOGNITO_WIN, 185 { PRS_THEME_FRAME_INCOGNITO_WIN, IDR_THEME_FRAME_INCOGNITO_WIN,
182 "theme_frame_incognito" }, 186 "theme_frame_incognito" },
183 { PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN, 187 { PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN,
184 IDR_THEME_FRAME_INCOGNITO_INACTIVE_WIN, 188 IDR_THEME_FRAME_INCOGNITO_INACTIVE_WIN,
185 "theme_frame_incognito_inactive" }, 189 "theme_frame_incognito_inactive" },
186 { PRS_THEME_TOOLBAR_WIN, IDR_THEME_TOOLBAR_WIN, 190 { PRS_THEME_TOOLBAR_WIN, IDR_THEME_TOOLBAR_WIN,
187 "theme_toolbar" }, 191 "theme_toolbar" },
188 { PRS_THEME_TAB_BACKGROUND_WIN, IDR_THEME_TAB_BACKGROUND_WIN, 192 { PRS_THEME_TAB_BACKGROUND_OVERLAY_WIN, IDR_THEME_TAB_BACKGROUND_OVERLAY_WIN,
189 "theme_tab_background" }, 193 "theme_tab_background" },
190 { PRS_THEME_TAB_BACKGROUND_INCOGNITO_WIN, 194 { PRS_THEME_TAB_BACKGROUND_INCOGNITO_OVERLAY_WIN,
191 IDR_THEME_TAB_BACKGROUND_INCOGNITO_WIN, 195 IDR_THEME_TAB_BACKGROUND_INCOGNITO_OVERLAY_WIN,
192 "theme_tab_background_incognito" }, 196 "theme_tab_background_incognito" },
193 }; 197 };
194 const size_t kPersistingImagesWinDesktopAuraLength = 198 const size_t kPersistingImagesWinDesktopAuraLength =
195 arraysize(kPersistingImagesWinDesktopAura); 199 arraysize(kPersistingImagesWinDesktopAura);
196 #endif 200 #endif
197 201
198 int GetPersistentIDByNameHelper(const std::string& key, 202 int GetPersistentIDByNameHelper(const std::string& key,
199 const PersistingImagesTable* image_table, 203 const PersistingImagesTable* image_table,
200 size_t image_table_size) { 204 size_t image_table_size) {
201 for (size_t i = 0; i < image_table_size; ++i) { 205 for (size_t i = 0; i < image_table_size; ++i) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE }, 347 ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE },
344 #if defined(OS_WIN) && defined(USE_AURA) 348 #if defined(OS_WIN) && defined(USE_AURA)
345 { PRS_THEME_FRAME_WIN, ThemeProperties::TINT_FRAME }, 349 { PRS_THEME_FRAME_WIN, ThemeProperties::TINT_FRAME },
346 { PRS_THEME_FRAME_INACTIVE_WIN, ThemeProperties::TINT_FRAME_INACTIVE }, 350 { PRS_THEME_FRAME_INACTIVE_WIN, ThemeProperties::TINT_FRAME_INACTIVE },
347 { PRS_THEME_FRAME_INCOGNITO_WIN, ThemeProperties::TINT_FRAME_INCOGNITO }, 351 { PRS_THEME_FRAME_INCOGNITO_WIN, ThemeProperties::TINT_FRAME_INCOGNITO },
348 { PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN, 352 { PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN,
349 ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE }, 353 ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE },
350 #endif 354 #endif
351 }; 355 };
352 356
353 // Mapping used in GenerateTabBackgroundImages() to associate what frame image 357 // Mapping used in CreateTabBackgroundImages() to associate what frame image
354 // goes with which tab background. 358 // goes with which tab background.
355 IntToIntTable kTabBackgroundMap[] = { 359 IntToIntTable kTabBackgroundMap[] = {
356 { PRS_THEME_TAB_BACKGROUND, PRS_THEME_FRAME }, 360 { PRS_THEME_TAB_BACKGROUND, PRS_THEME_FRAME },
357 { PRS_THEME_TAB_BACKGROUND_INCOGNITO, PRS_THEME_FRAME_INCOGNITO }, 361 { PRS_THEME_TAB_BACKGROUND_INCOGNITO, PRS_THEME_FRAME_INCOGNITO },
358 #if defined(OS_WIN) && defined(USE_AURA) 362 #if defined(OS_WIN) && defined(USE_AURA)
359 { PRS_THEME_TAB_BACKGROUND_WIN, PRS_THEME_FRAME_WIN }, 363 { PRS_THEME_TAB_BACKGROUND_WIN, PRS_THEME_FRAME_WIN },
360 { PRS_THEME_TAB_BACKGROUND_INCOGNITO_WIN, PRS_THEME_FRAME_INCOGNITO_WIN }, 364 { PRS_THEME_TAB_BACKGROUND_INCOGNITO_WIN, PRS_THEME_FRAME_INCOGNITO_WIN },
361 #endif 365 #endif
362 }; 366 };
363 367
364 struct CropEntry { 368 struct CropEntry {
365 int prs_id; 369 int prs_id;
366 370
367 // The maximum useful height of the image at |prs_id|. 371 // The maximum useful height of the image at |prs_id|.
368 int max_height; 372 int max_height;
369 373
370 // Whether cropping the image at |prs_id| should be skipped on OSes which 374 // Whether cropping the image at |prs_id| should be skipped on OSes which
371 // have a frame border to the left and right of the web contents. 375 // have a frame border to the left and right of the web contents.
372 // This should be true for images which can be used to decorate the border to 376 // This should be true for images which can be used to decorate the border to
373 // the left and the right of the web contents. 377 // the left and the right of the web contents.
374 bool skip_if_frame_border; 378 bool skip_if_frame_border;
375 }; 379 };
376 380
377 // The images which should be cropped before being saved to the data pack. The 381 // The images which should be cropped before being saved to the data pack. The
378 // maximum heights are meant to be conservative as to give room for the UI to 382 // maximum heights are meant to be conservative as to give room for the UI to
379 // change without the maximum heights having to be modified. 383 // change without the maximum heights having to be modified.
380 // |kThemePackVersion| must be incremented if any of the maximum heights below 384 // |kThemePackVersion| must be incremented if any of the maximum heights below
381 // are modified. 385 // are modified.
382 struct CropEntry kImagesToCrop[] = { 386 CropEntry kImagesToCrop[] = {
383 { PRS_THEME_FRAME, 120, true }, 387 { PRS_THEME_FRAME, 120, true },
384 { PRS_THEME_FRAME_INACTIVE, 120, true }, 388 { PRS_THEME_FRAME_INACTIVE, 120, true },
385 { PRS_THEME_FRAME_INCOGNITO, 120, true }, 389 { PRS_THEME_FRAME_INCOGNITO, 120, true },
386 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, 120, true }, 390 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, 120, true },
387 { PRS_THEME_FRAME_OVERLAY, 120, true }, 391 { PRS_THEME_FRAME_OVERLAY, 120, true },
388 { PRS_THEME_FRAME_OVERLAY_INACTIVE, 120, true }, 392 { PRS_THEME_FRAME_OVERLAY_INACTIVE, 120, true },
389 { PRS_THEME_TOOLBAR, 200, false }, 393 { PRS_THEME_TOOLBAR, 200, false },
394 { PRS_THEME_TAB_BACKGROUND_OVERLAY, 80, false },
395 { PRS_THEME_TAB_BACKGROUND_INCOGNITO_OVERLAY, 80, false },
396 { PRS_THEME_TAB_BACKGROUND_V_OVERLAY, 80, false },
397 { PRS_THEME_TAB_BACKGROUND, 120, false },
398 { PRS_THEME_TAB_BACKGROUND_INCOGNITO, 120, false },
390 { PRS_THEME_BUTTON_BACKGROUND, 60, false }, 399 { PRS_THEME_BUTTON_BACKGROUND, 60, false },
391 { PRS_THEME_WINDOW_CONTROL_BACKGROUND, 50, false }, 400 { PRS_THEME_WINDOW_CONTROL_BACKGROUND, 50, false },
392 #if defined(OS_WIN) && defined(USE_AURA) 401 #if defined(OS_WIN) && defined(USE_AURA)
393 { PRS_THEME_TOOLBAR_WIN, 200, false } 402 { PRS_THEME_TOOLBAR_WIN, 200, false },
403 { PRS_THEME_TAB_BACKGROUND_OVERLAY_WIN, 80, false },
404 { PRS_THEME_TAB_BACKGROUND_INCOGNITO_OVERLAY_WIN, 80, false },
405 { PRS_THEME_TAB_BACKGROUND_WIN, 120, false },
406 { PRS_THEME_TAB_BACKGROUND_INCOGNITO_WIN, 120, false }
394 #endif 407 #endif
395 }; 408 };
396 409
397
398 // A list of images that don't need tinting or any other modification and can 410 // A list of images that don't need tinting or any other modification and can
399 // be byte-copied directly into the finished DataPack. This should contain the 411 // be byte-copied directly into the finished DataPack. This should contain the
400 // persistent IDs for all themeable image IDs that aren't in kFrameTintMap, 412 // persistent IDs for all themeable image IDs that aren't in kFrameTintMap,
401 // kTabBackgroundMap or kImagesToCrop. 413 // kTabBackgroundMap or kImagesToCrop.
402 const int kPreloadIDs[] = { 414 const int kPreloadIDs[] = {
403 PRS_THEME_NTP_BACKGROUND, 415 PRS_THEME_NTP_BACKGROUND,
404 PRS_THEME_NTP_ATTRIBUTION, 416 PRS_THEME_NTP_ATTRIBUTION,
405 }; 417 };
406 418
407 // Returns true if this OS uses a browser frame which has a non zero width to 419 // Returns true if this OS uses a browser frame which has a non zero width to
(...skipping 20 matching lines...) Expand all
428 char* data = reinterpret_cast<char*>(&(raw_data.front())); 440 char* data = reinterpret_cast<char*>(&(raw_data.front()));
429 if (file.ReadUntilComplete(data, size) == avail) 441 if (file.ReadUntilComplete(data, size) == avail)
430 return base::RefCountedBytes::TakeVector(&raw_data); 442 return base::RefCountedBytes::TakeVector(&raw_data);
431 } 443 }
432 } 444 }
433 } 445 }
434 446
435 return NULL; 447 return NULL;
436 } 448 }
437 449
438 // Shifts an image's HSL values. The caller is responsible for deleting 450 // Returns an image which is cropped based on the maximum height for
439 // the returned image. 451 // |destination_prs_id|. This method is a no-op if no cropping is necessary.
440 gfx::Image CreateHSLShiftedImage(const gfx::Image& image, 452 gfx::Image CreateCroppedImage(const gfx::Image& source_image,
441 const color_utils::HSL& hsl_shift) { 453 int destination_prs_id) {
442 const gfx::ImageSkia* src_image = image.ToImageSkia(); 454 bool has_frame_border = HasFrameBorder();
455 for (size_t i = 0; i < arraysize(kImagesToCrop); ++i) {
456 if (has_frame_border && kImagesToCrop[i].skip_if_frame_border)
457 continue;
458
459 if (kImagesToCrop[i].prs_id != destination_prs_id)
460 continue;
461
462 int crop_height = kImagesToCrop[i].max_height;
463 gfx::ImageSkia image_skia = source_image.AsImageSkia();
464 return gfx::Image(gfx::ImageSkiaOperations::ExtractSubset(
465 image_skia, gfx::Rect(0, 0, image_skia.width(), crop_height)));
466 }
467 return source_image;
468 }
469
470 // Retuns an image which is cropped based on the maximum height for
471 // |destination_prs_id| and which is shifted by |hsl_shift|.
472 gfx::Image CreateHSLShiftedAndCroppedImage(const gfx::Image& image,
473 const color_utils::HSL& hsl_shift,
474 int destination_prs_id) {
475 gfx::Image cropped = CreateCroppedImage(image, destination_prs_id);
443 return gfx::Image(gfx::ImageSkiaOperations::CreateHSLShiftedImage( 476 return gfx::Image(gfx::ImageSkiaOperations::CreateHSLShiftedImage(
444 *src_image, hsl_shift)); 477 cropped.AsImageSkia(), hsl_shift));
445 } 478 }
446 479
447 // Computes a bitmap at one scale from a bitmap at a different scale. 480 // Computes a bitmap at one scale from a bitmap at a different scale.
448 SkBitmap CreateLowQualityResizedBitmap(const SkBitmap& source_bitmap, 481 SkBitmap CreateLowQualityResizedBitmap(const SkBitmap& source_bitmap,
449 ui::ScaleFactor source_scale_factor, 482 ui::ScaleFactor source_scale_factor,
450 ui::ScaleFactor desired_scale_factor) { 483 ui::ScaleFactor desired_scale_factor) {
451 gfx::Size scaled_size = gfx::ToCeiledSize( 484 gfx::Size scaled_size = gfx::ToCeiledSize(
452 gfx::ScaleSize(gfx::Size(source_bitmap.width(), 485 gfx::ScaleSize(gfx::Size(source_bitmap.width(),
453 source_bitmap.height()), 486 source_bitmap.height()),
454 ui::GetScaleFactorScale(desired_scale_factor) / 487 ui::GetScaleFactorScale(desired_scale_factor) /
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 } 607 }
575 608
576 PngMap png_map_; 609 PngMap png_map_;
577 610
578 typedef std::map<ui::ScaleFactor, SkBitmap> BitmapMap; 611 typedef std::map<ui::ScaleFactor, SkBitmap> BitmapMap;
579 BitmapMap bitmap_map_; 612 BitmapMap bitmap_map_;
580 613
581 DISALLOW_COPY_AND_ASSIGN(ThemeImagePngSource); 614 DISALLOW_COPY_AND_ASSIGN(ThemeImagePngSource);
582 }; 615 };
583 616
584 class TabBackgroundImageSource: public gfx::CanvasImageSource {
585 public:
586 TabBackgroundImageSource(const gfx::ImageSkia& image_to_tint,
587 const gfx::ImageSkia& overlay,
588 const color_utils::HSL& hsl_shift,
589 int vertical_offset)
590 : gfx::CanvasImageSource(image_to_tint.size(), false),
591 image_to_tint_(image_to_tint),
592 overlay_(overlay),
593 hsl_shift_(hsl_shift),
594 vertical_offset_(vertical_offset) {
595 }
596
597 virtual ~TabBackgroundImageSource() {
598 }
599
600 // Overridden from CanvasImageSource:
601 virtual void Draw(gfx::Canvas* canvas) OVERRIDE {
602 gfx::ImageSkia bg_tint =
603 gfx::ImageSkiaOperations::CreateHSLShiftedImage(image_to_tint_,
604 hsl_shift_);
605 canvas->TileImageInt(bg_tint, 0, vertical_offset_, 0, 0,
606 size().width(), size().height());
607
608 // If they've provided a custom image, overlay it.
609 if (!overlay_.isNull()) {
610 canvas->TileImageInt(overlay_, 0, 0, size().width(),
611 overlay_.height());
612 }
613 }
614
615 private:
616 const gfx::ImageSkia image_to_tint_;
617 const gfx::ImageSkia overlay_;
618 const color_utils::HSL hsl_shift_;
619 const int vertical_offset_;
620
621 DISALLOW_COPY_AND_ASSIGN(TabBackgroundImageSource);
622 };
623
624 } // namespace 617 } // namespace
625 618
626 BrowserThemePack::~BrowserThemePack() { 619 BrowserThemePack::~BrowserThemePack() {
627 if (!data_pack_.get()) { 620 if (!data_pack_.get()) {
628 delete header_; 621 delete header_;
629 delete [] tints_; 622 delete [] tints_;
630 delete [] colors_; 623 delete [] colors_;
631 delete [] display_properties_; 624 delete [] display_properties_;
632 delete [] source_images_; 625 delete [] source_images_;
633 } 626 }
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 } 1292 }
1300 1293
1301 void BrowserThemePack::CreateImages(ImageCache* images) const { 1294 void BrowserThemePack::CreateImages(ImageCache* images) const {
1302 CropImages(images); 1295 CropImages(images);
1303 CreateFrameImages(images); 1296 CreateFrameImages(images);
1304 CreateTintedButtons(GetTintInternal(ThemeProperties::TINT_BUTTONS), images); 1297 CreateTintedButtons(GetTintInternal(ThemeProperties::TINT_BUTTONS), images);
1305 CreateTabBackgroundImages(images); 1298 CreateTabBackgroundImages(images);
1306 } 1299 }
1307 1300
1308 void BrowserThemePack::CropImages(ImageCache* images) const { 1301 void BrowserThemePack::CropImages(ImageCache* images) const {
1309 bool has_frame_border = HasFrameBorder(); 1302 ImageCache temp_output;
1310 for (size_t i = 0; i < arraysize(kImagesToCrop); ++i) { 1303 for (ImageCache::const_iterator it = images->begin();
1311 if (has_frame_border && kImagesToCrop[i].skip_if_frame_border) 1304 it != images->end(); ++it) {
1312 continue; 1305 temp_output[it->first] = CreateCroppedImage(it->second, it->first);
1313
1314 int prs_id = kImagesToCrop[i].prs_id;
1315 ImageCache::iterator it = images->find(prs_id);
1316 if (it == images->end())
1317 continue;
1318
1319 int crop_height = kImagesToCrop[i].max_height;
1320 gfx::ImageSkia image_skia = it->second.AsImageSkia();
1321 (*images)[prs_id] = gfx::Image(gfx::ImageSkiaOperations::ExtractSubset(
1322 image_skia, gfx::Rect(0, 0, image_skia.width(), crop_height)));
1323 } 1306 }
1307 MergeImageCaches(temp_output, images);
1324 } 1308 }
1325 1309
1326 void BrowserThemePack::CreateFrameImages(ImageCache* images) const { 1310 void BrowserThemePack::CreateFrameImages(ImageCache* images) const {
1327 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1311 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1328 1312
1329 // Create all the output images in a separate cache and move them back into 1313 // Create all the output images in a separate cache and move them back into
1330 // the input images because there can be name collisions. 1314 // the input images because there can be name collisions.
1331 ImageCache temp_output; 1315 ImageCache temp_output;
1332 1316
1333 for (size_t i = 0; i < arraysize(kFrameTintMap); ++i) { 1317 for (size_t i = 0; i < arraysize(kFrameTintMap); ++i) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 // the default frame. 1368 // the default frame.
1385 frame = rb.GetImageNamed(IDR_THEME_FRAME); 1369 frame = rb.GetImageNamed(IDR_THEME_FRAME);
1386 #if defined(OS_WIN) && defined(USE_AURA) 1370 #if defined(OS_WIN) && defined(USE_AURA)
1387 if (prs_id >= PRS_THEME_FRAME_WIN && 1371 if (prs_id >= PRS_THEME_FRAME_WIN &&
1388 prs_id <= PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN) { 1372 prs_id <= PRS_THEME_FRAME_INCOGNITO_INACTIVE_WIN) {
1389 frame = rb.GetImageNamed(IDR_THEME_FRAME_WIN); 1373 frame = rb.GetImageNamed(IDR_THEME_FRAME_WIN);
1390 } 1374 }
1391 #endif 1375 #endif
1392 } 1376 }
1393 if (!frame.IsEmpty()) { 1377 if (!frame.IsEmpty()) {
1394 temp_output[prs_id] = CreateHSLShiftedImage( 1378 temp_output[prs_id] = CreateHSLShiftedAndCroppedImage(
1395 frame, GetTintInternal(kFrameTintMap[i].value)); 1379 frame, GetTintInternal(kFrameTintMap[i].value), prs_id);
1396 } 1380 }
1397 } 1381 }
1398 MergeImageCaches(temp_output, images); 1382 MergeImageCaches(temp_output, images);
1399 } 1383 }
1400 1384
1401 void BrowserThemePack::CreateTintedButtons( 1385 void BrowserThemePack::CreateTintedButtons(
1402 const color_utils::HSL& button_tint, 1386 const color_utils::HSL& button_tint,
1403 ImageCache* processed_images) const { 1387 ImageCache* processed_images) const {
1404 if (button_tint.h != -1 || button_tint.s != -1 || button_tint.l != -1) { 1388 if (button_tint.h != -1 || button_tint.s != -1 || button_tint.l != -1) {
1405 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1389 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1406 const std::set<int>& idr_ids = 1390 const std::set<int>& idr_ids =
1407 ThemeProperties::GetTintableToolbarButtons(); 1391 ThemeProperties::GetTintableToolbarButtons();
1408 for (std::set<int>::const_iterator it = idr_ids.begin(); 1392 for (std::set<int>::const_iterator it = idr_ids.begin();
1409 it != idr_ids.end(); ++it) { 1393 it != idr_ids.end(); ++it) {
1410 int prs_id = GetPersistentIDByIDR(*it); 1394 int prs_id = GetPersistentIDByIDR(*it);
1411 DCHECK(prs_id > 0); 1395 DCHECK(prs_id > 0);
1412 1396
1413 // Fetch the image by IDR... 1397 // Fetch the image by IDR...
1414 gfx::Image& button = rb.GetImageNamed(*it); 1398 gfx::Image& button = rb.GetImageNamed(*it);
1415 1399
1416 // but save a version with the persistent ID. 1400 // but save a version with the persistent ID.
1417 (*processed_images)[prs_id] = 1401 (*processed_images)[prs_id] =
1418 CreateHSLShiftedImage(button, button_tint); 1402 CreateHSLShiftedAndCroppedImage(button, button_tint, prs_id);
1419 } 1403 }
1420 } 1404 }
1421 } 1405 }
1422 1406
1423 void BrowserThemePack::CreateTabBackgroundImages(ImageCache* images) const { 1407 void BrowserThemePack::CreateTabBackgroundImages(ImageCache* images) const {
1424 ImageCache temp_output; 1408 ImageCache temp_output;
1425 for (size_t i = 0; i < arraysize(kTabBackgroundMap); ++i) { 1409 for (size_t i = 0; i < arraysize(kTabBackgroundMap); ++i) {
1426 int prs_id = kTabBackgroundMap[i].key; 1410 int prs_frame_id = kTabBackgroundMap[i].value;
1427 int prs_base_id = kTabBackgroundMap[i].value; 1411 ImageCache::const_iterator frame_it = images->find(prs_frame_id);
1412 if (frame_it == images->end()) {
1413 // There is no image to tint.
1414 continue;
1415 }
1428 1416
1429 // We only need to generate the background tab images if we were provided 1417 int prs_dest_id = kTabBackgroundMap[i].key;
1430 // with a PRS_THEME_FRAME. 1418 color_utils::HSL tint = GetTintInternal(
1431 ImageCache::const_iterator it = images->find(prs_base_id); 1419 ThemeProperties::TINT_BACKGROUND_TAB);
1432 if (it != images->end()) { 1420 temp_output[prs_dest_id] = CreateHSLShiftedAndCroppedImage(
1433 gfx::ImageSkia image_to_tint = (it->second).AsImageSkia(); 1421 frame_it->second, tint, prs_dest_id);
1434 color_utils::HSL hsl_shift = GetTintInternal(
1435 ThemeProperties::TINT_BACKGROUND_TAB);
1436 int vertical_offset = images->count(prs_id)
1437 ? kRestoredTabVerticalOffset : 0;
1438
1439 gfx::ImageSkia overlay;
1440 ImageCache::const_iterator overlay_it = images->find(prs_id);
1441 if (overlay_it != images->end())
1442 overlay = overlay_it->second.AsImageSkia();
1443
1444 gfx::ImageSkiaSource* source = new TabBackgroundImageSource(
1445 image_to_tint, overlay, hsl_shift, vertical_offset);
1446 // ImageSkia takes ownership of |source|.
1447 temp_output[prs_id] = gfx::Image(gfx::ImageSkia(source,
1448 image_to_tint.size()));
1449 }
1450 } 1422 }
1451 MergeImageCaches(temp_output, images); 1423 MergeImageCaches(temp_output, images);
1452 } 1424 }
1453 1425
1454 void BrowserThemePack::RepackImages(const ImageCache& images, 1426 void BrowserThemePack::RepackImages(const ImageCache& images,
1455 RawImages* reencoded_images) const { 1427 RawImages* reencoded_images) const {
1456 typedef std::vector<ui::ScaleFactor> ScaleFactors; 1428 typedef std::vector<ui::ScaleFactor> ScaleFactors;
1457 for (ImageCache::const_iterator it = images.begin(); 1429 for (ImageCache::const_iterator it = images.begin();
1458 it != images.end(); ++it) { 1430 it != images.end(); ++it) {
1459 gfx::ImageSkia image_skia = *it->second.ToImageSkia(); 1431 gfx::ImageSkia image_skia = *it->second.ToImageSkia();
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1604 false, 1576 false,
1605 &bitmap_data)) { 1577 &bitmap_data)) {
1606 NOTREACHED() << "Unable to encode theme image for prs_id=" 1578 NOTREACHED() << "Unable to encode theme image for prs_id="
1607 << prs_id << " for scale_factor=" << scale_factors_[i]; 1579 << prs_id << " for scale_factor=" << scale_factors_[i];
1608 break; 1580 break;
1609 } 1581 }
1610 image_memory_[scaled_raw_id] = 1582 image_memory_[scaled_raw_id] =
1611 base::RefCountedBytes::TakeVector(&bitmap_data); 1583 base::RefCountedBytes::TakeVector(&bitmap_data);
1612 } 1584 }
1613 } 1585 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698