| 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/themes/browser_theme_pack.h" | 5 #include "chrome/browser/themes/browser_theme_pack.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 // A non-changing integer ID meant to be saved in theme packs. This ID must | 89 // A non-changing integer ID meant to be saved in theme packs. This ID must |
| 90 // not change between versions of chrome. | 90 // not change between versions of chrome. |
| 91 int persistent_id; | 91 int persistent_id; |
| 92 | 92 |
| 93 // The IDR that depends on the whims of GRIT and therefore changes whenever | 93 // The IDR that depends on the whims of GRIT and therefore changes whenever |
| 94 // someone adds a new resource. | 94 // someone adds a new resource. |
| 95 int idr_id; | 95 int idr_id; |
| 96 | 96 |
| 97 // String to check for when parsing theme manifests or NULL if this isn't | 97 // String to check for when parsing theme manifests or NULL if this isn't |
| 98 // supposed to be changeable by the user. | 98 // supposed to be changeable by the user. |
| 99 const char* const key; | 99 const char* key; |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 // IDR_* resource names change whenever new resources are added; use persistent | 102 // IDR_* resource names change whenever new resources are added; use persistent |
| 103 // IDs when storing to a cached pack. | 103 // IDs when storing to a cached pack. |
| 104 PersistingImagesTable kPersistingImages[] = { | 104 const PersistingImagesTable kPersistingImages[] = { |
| 105 {PRS_THEME_FRAME, IDR_THEME_FRAME, "theme_frame"}, | 105 {PRS_THEME_FRAME, IDR_THEME_FRAME, "theme_frame"}, |
| 106 {PRS_THEME_FRAME_INACTIVE, IDR_THEME_FRAME_INACTIVE, | 106 {PRS_THEME_FRAME_INACTIVE, IDR_THEME_FRAME_INACTIVE, |
| 107 "theme_frame_inactive"}, | 107 "theme_frame_inactive"}, |
| 108 {PRS_THEME_FRAME_INCOGNITO, IDR_THEME_FRAME_INCOGNITO, | 108 {PRS_THEME_FRAME_INCOGNITO, IDR_THEME_FRAME_INCOGNITO, |
| 109 "theme_frame_incognito"}, | 109 "theme_frame_incognito"}, |
| 110 {PRS_THEME_FRAME_INCOGNITO_INACTIVE, IDR_THEME_FRAME_INCOGNITO_INACTIVE, | 110 {PRS_THEME_FRAME_INCOGNITO_INACTIVE, IDR_THEME_FRAME_INCOGNITO_INACTIVE, |
| 111 "theme_frame_incognito_inactive"}, | 111 "theme_frame_incognito_inactive"}, |
| 112 {PRS_THEME_TOOLBAR, IDR_THEME_TOOLBAR, "theme_toolbar"}, | 112 {PRS_THEME_TOOLBAR, IDR_THEME_TOOLBAR, "theme_toolbar"}, |
| 113 {PRS_THEME_TAB_BACKGROUND, IDR_THEME_TAB_BACKGROUND, | 113 {PRS_THEME_TAB_BACKGROUND, IDR_THEME_TAB_BACKGROUND, |
| 114 "theme_tab_background"}, | 114 "theme_tab_background"}, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 std::unique_ptr<float[]> scales(new float[scale_factors.size()]); | 198 std::unique_ptr<float[]> scales(new float[scale_factors.size()]); |
| 199 for (size_t i = 0; i < scale_factors.size(); ++i) | 199 for (size_t i = 0; i < scale_factors.size(); ++i) |
| 200 scales[i] = ui::GetScaleForScaleFactor(scale_factors[i]); | 200 scales[i] = ui::GetScaleForScaleFactor(scale_factors[i]); |
| 201 std::string out_string = std::string( | 201 std::string out_string = std::string( |
| 202 reinterpret_cast<const char*>(scales.get()), | 202 reinterpret_cast<const char*>(scales.get()), |
| 203 scale_factors.size() * sizeof(float)); | 203 scale_factors.size() * sizeof(float)); |
| 204 return out_string; | 204 return out_string; |
| 205 } | 205 } |
| 206 | 206 |
| 207 struct StringToIntTable { | 207 struct StringToIntTable { |
| 208 const char* const key; | 208 const char* key; |
| 209 ThemeProperties::OverwritableByUserThemeProperty id; | 209 ThemeProperties::OverwritableByUserThemeProperty id; |
| 210 }; | 210 }; |
| 211 | 211 |
| 212 // Strings used by themes to identify tints in the JSON. | 212 // Strings used by themes to identify tints in the JSON. |
| 213 StringToIntTable kTintTable[] = { | 213 const StringToIntTable kTintTable[] = { |
| 214 { "buttons", ThemeProperties::TINT_BUTTONS }, | 214 { "buttons", ThemeProperties::TINT_BUTTONS }, |
| 215 { "frame", ThemeProperties::TINT_FRAME }, | 215 { "frame", ThemeProperties::TINT_FRAME }, |
| 216 { "frame_inactive", ThemeProperties::TINT_FRAME_INACTIVE }, | 216 { "frame_inactive", ThemeProperties::TINT_FRAME_INACTIVE }, |
| 217 { "frame_incognito", ThemeProperties::TINT_FRAME_INCOGNITO }, | 217 { "frame_incognito", ThemeProperties::TINT_FRAME_INCOGNITO }, |
| 218 { "frame_incognito_inactive", | 218 { "frame_incognito_inactive", |
| 219 ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE }, | 219 ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE }, |
| 220 { "background_tab", ThemeProperties::TINT_BACKGROUND_TAB }, | 220 { "background_tab", ThemeProperties::TINT_BACKGROUND_TAB }, |
| 221 }; | 221 }; |
| 222 const size_t kTintTableLength = arraysize(kTintTable); | 222 const size_t kTintTableLength = arraysize(kTintTable); |
| 223 | 223 |
| 224 // Strings used by themes to identify colors in the JSON. | 224 // Strings used by themes to identify colors in the JSON. |
| 225 StringToIntTable kColorTable[] = { | 225 const StringToIntTable kColorTable[] = { |
| 226 { "frame", ThemeProperties::COLOR_FRAME }, | 226 { "frame", ThemeProperties::COLOR_FRAME }, |
| 227 { "frame_inactive", ThemeProperties::COLOR_FRAME_INACTIVE }, | 227 { "frame_inactive", ThemeProperties::COLOR_FRAME_INACTIVE }, |
| 228 { "frame_incognito", ThemeProperties::COLOR_FRAME_INCOGNITO }, | 228 { "frame_incognito", ThemeProperties::COLOR_FRAME_INCOGNITO }, |
| 229 { "frame_incognito_inactive", | 229 { "frame_incognito_inactive", |
| 230 ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE }, | 230 ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE }, |
| 231 { "toolbar", ThemeProperties::COLOR_TOOLBAR }, | 231 { "toolbar", ThemeProperties::COLOR_TOOLBAR }, |
| 232 { "tab_text", ThemeProperties::COLOR_TAB_TEXT }, | 232 { "tab_text", ThemeProperties::COLOR_TAB_TEXT }, |
| 233 { "tab_background_text", ThemeProperties::COLOR_BACKGROUND_TAB_TEXT }, | 233 { "tab_background_text", ThemeProperties::COLOR_BACKGROUND_TAB_TEXT }, |
| 234 { "bookmark_text", ThemeProperties::COLOR_BOOKMARK_TEXT }, | 234 { "bookmark_text", ThemeProperties::COLOR_BOOKMARK_TEXT }, |
| 235 { "ntp_background", ThemeProperties::COLOR_NTP_BACKGROUND }, | 235 { "ntp_background", ThemeProperties::COLOR_NTP_BACKGROUND }, |
| 236 { "ntp_text", ThemeProperties::COLOR_NTP_TEXT }, | 236 { "ntp_text", ThemeProperties::COLOR_NTP_TEXT }, |
| 237 { "ntp_link", ThemeProperties::COLOR_NTP_LINK }, | 237 { "ntp_link", ThemeProperties::COLOR_NTP_LINK }, |
| 238 { "ntp_link_underline", ThemeProperties::COLOR_NTP_LINK_UNDERLINE }, | 238 { "ntp_link_underline", ThemeProperties::COLOR_NTP_LINK_UNDERLINE }, |
| 239 { "ntp_header", ThemeProperties::COLOR_NTP_HEADER }, | 239 { "ntp_header", ThemeProperties::COLOR_NTP_HEADER }, |
| 240 { "ntp_section", ThemeProperties::COLOR_NTP_SECTION }, | 240 { "ntp_section", ThemeProperties::COLOR_NTP_SECTION }, |
| 241 { "ntp_section_text", ThemeProperties::COLOR_NTP_SECTION_TEXT }, | 241 { "ntp_section_text", ThemeProperties::COLOR_NTP_SECTION_TEXT }, |
| 242 { "ntp_section_link", ThemeProperties::COLOR_NTP_SECTION_LINK }, | 242 { "ntp_section_link", ThemeProperties::COLOR_NTP_SECTION_LINK }, |
| 243 { "ntp_section_link_underline", | 243 { "ntp_section_link_underline", |
| 244 ThemeProperties::COLOR_NTP_SECTION_LINK_UNDERLINE }, | 244 ThemeProperties::COLOR_NTP_SECTION_LINK_UNDERLINE }, |
| 245 { "button_background", ThemeProperties::COLOR_BUTTON_BACKGROUND }, | 245 { "button_background", ThemeProperties::COLOR_BUTTON_BACKGROUND }, |
| 246 }; | 246 }; |
| 247 const size_t kColorTableLength = arraysize(kColorTable); | 247 const size_t kColorTableLength = arraysize(kColorTable); |
| 248 | 248 |
| 249 // Strings used by themes to identify display properties keys in JSON. | 249 // Strings used by themes to identify display properties keys in JSON. |
| 250 StringToIntTable kDisplayProperties[] = { | 250 const StringToIntTable kDisplayProperties[] = { |
| 251 { "ntp_background_alignment", | 251 { "ntp_background_alignment", |
| 252 ThemeProperties::NTP_BACKGROUND_ALIGNMENT }, | 252 ThemeProperties::NTP_BACKGROUND_ALIGNMENT }, |
| 253 { "ntp_background_repeat", ThemeProperties::NTP_BACKGROUND_TILING }, | 253 { "ntp_background_repeat", ThemeProperties::NTP_BACKGROUND_TILING }, |
| 254 { "ntp_logo_alternate", ThemeProperties::NTP_LOGO_ALTERNATE }, | 254 { "ntp_logo_alternate", ThemeProperties::NTP_LOGO_ALTERNATE }, |
| 255 }; | 255 }; |
| 256 const size_t kDisplayPropertiesSize = arraysize(kDisplayProperties); | 256 const size_t kDisplayPropertiesSize = arraysize(kDisplayProperties); |
| 257 | 257 |
| 258 int GetIntForString(const std::string& key, | 258 int GetIntForString(const std::string& key, |
| 259 StringToIntTable* table, | 259 const StringToIntTable* table, |
| 260 size_t table_length) { | 260 size_t table_length) { |
| 261 for (size_t i = 0; i < table_length; ++i) { | 261 for (size_t i = 0; i < table_length; ++i) { |
| 262 if (base::LowerCaseEqualsASCII(key, table[i].key)) { | 262 if (base::LowerCaseEqualsASCII(key, table[i].key)) { |
| 263 return table[i].id; | 263 return table[i].id; |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 | 266 |
| 267 return -1; | 267 return -1; |
| 268 } | 268 } |
| 269 | 269 |
| 270 struct IntToIntTable { | 270 struct IntToIntTable { |
| 271 int key; | 271 int key; |
| 272 int value; | 272 int value; |
| 273 }; | 273 }; |
| 274 | 274 |
| 275 // Mapping used in CreateFrameImages() to associate frame images with the | 275 // Mapping used in CreateFrameImages() to associate frame images with the |
| 276 // tint ID that should maybe be applied to it. | 276 // tint ID that should maybe be applied to it. |
| 277 IntToIntTable kFrameTintMap[] = { | 277 const IntToIntTable kFrameTintMap[] = { |
| 278 { PRS_THEME_FRAME, ThemeProperties::TINT_FRAME }, | 278 { PRS_THEME_FRAME, ThemeProperties::TINT_FRAME }, |
| 279 { PRS_THEME_FRAME_INACTIVE, ThemeProperties::TINT_FRAME_INACTIVE }, | 279 { PRS_THEME_FRAME_INACTIVE, ThemeProperties::TINT_FRAME_INACTIVE }, |
| 280 { PRS_THEME_FRAME_OVERLAY, ThemeProperties::TINT_FRAME }, | 280 { PRS_THEME_FRAME_OVERLAY, ThemeProperties::TINT_FRAME }, |
| 281 { PRS_THEME_FRAME_OVERLAY_INACTIVE, | 281 { PRS_THEME_FRAME_OVERLAY_INACTIVE, |
| 282 ThemeProperties::TINT_FRAME_INACTIVE }, | 282 ThemeProperties::TINT_FRAME_INACTIVE }, |
| 283 { PRS_THEME_FRAME_INCOGNITO, ThemeProperties::TINT_FRAME_INCOGNITO }, | 283 { PRS_THEME_FRAME_INCOGNITO, ThemeProperties::TINT_FRAME_INCOGNITO }, |
| 284 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, | 284 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, |
| 285 ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE }, | 285 ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE }, |
| 286 }; | 286 }; |
| 287 | 287 |
| 288 // Mapping used in GenerateTabBackgroundImages() to associate what frame image | 288 // Mapping used in GenerateTabBackgroundImages() to associate what frame image |
| 289 // goes with which tab background. | 289 // goes with which tab background. |
| 290 IntToIntTable kTabBackgroundMap[] = { | 290 const IntToIntTable kTabBackgroundMap[] = { |
| 291 { PRS_THEME_TAB_BACKGROUND, PRS_THEME_FRAME }, | 291 { PRS_THEME_TAB_BACKGROUND, PRS_THEME_FRAME }, |
| 292 { PRS_THEME_TAB_BACKGROUND_INCOGNITO, PRS_THEME_FRAME_INCOGNITO }, | 292 { PRS_THEME_TAB_BACKGROUND_INCOGNITO, PRS_THEME_FRAME_INCOGNITO }, |
| 293 }; | 293 }; |
| 294 | 294 |
| 295 struct CropEntry { | 295 struct CropEntry { |
| 296 int prs_id; | 296 int prs_id; |
| 297 | 297 |
| 298 // The maximum useful height of the image at |prs_id|. | 298 // The maximum useful height of the image at |prs_id|. |
| 299 int max_height; | 299 int max_height; |
| 300 | 300 |
| 301 // Whether cropping the image at |prs_id| should be skipped on OSes which | 301 // Whether cropping the image at |prs_id| should be skipped on OSes which |
| 302 // have a frame border to the left and right of the web contents. | 302 // have a frame border to the left and right of the web contents. |
| 303 // This should be true for images which can be used to decorate the border to | 303 // This should be true for images which can be used to decorate the border to |
| 304 // the left and the right of the web contents. | 304 // the left and the right of the web contents. |
| 305 bool skip_if_frame_border; | 305 bool skip_if_frame_border; |
| 306 }; | 306 }; |
| 307 | 307 |
| 308 // The images which should be cropped before being saved to the data pack. The | 308 // The images which should be cropped before being saved to the data pack. The |
| 309 // maximum heights are meant to be conservative as to give room for the UI to | 309 // maximum heights are meant to be conservative as to give room for the UI to |
| 310 // change without the maximum heights having to be modified. | 310 // change without the maximum heights having to be modified. |
| 311 // |kThemePackVersion| must be incremented if any of the maximum heights below | 311 // |kThemePackVersion| must be incremented if any of the maximum heights below |
| 312 // are modified. | 312 // are modified. |
| 313 struct CropEntry kImagesToCrop[] = { | 313 const struct CropEntry kImagesToCrop[] = { |
| 314 { PRS_THEME_FRAME, 120, true }, | 314 { PRS_THEME_FRAME, 120, true }, |
| 315 { PRS_THEME_FRAME_INACTIVE, 120, true }, | 315 { PRS_THEME_FRAME_INACTIVE, 120, true }, |
| 316 { PRS_THEME_FRAME_INCOGNITO, 120, true }, | 316 { PRS_THEME_FRAME_INCOGNITO, 120, true }, |
| 317 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, 120, true }, | 317 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, 120, true }, |
| 318 { PRS_THEME_FRAME_OVERLAY, 120, true }, | 318 { PRS_THEME_FRAME_OVERLAY, 120, true }, |
| 319 { PRS_THEME_FRAME_OVERLAY_INACTIVE, 120, true }, | 319 { PRS_THEME_FRAME_OVERLAY_INACTIVE, 120, true }, |
| 320 { PRS_THEME_TOOLBAR, 200, false }, | 320 { PRS_THEME_TOOLBAR, 200, false }, |
| 321 { PRS_THEME_BUTTON_BACKGROUND, 60, false }, | 321 { PRS_THEME_BUTTON_BACKGROUND, 60, false }, |
| 322 { PRS_THEME_WINDOW_CONTROL_BACKGROUND, 50, false }, | 322 { PRS_THEME_WINDOW_CONTROL_BACKGROUND, 50, false }, |
| 323 }; | 323 }; |
| (...skipping 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1452 false, | 1452 false, |
| 1453 &bitmap_data)) { | 1453 &bitmap_data)) { |
| 1454 NOTREACHED() << "Unable to encode theme image for prs_id=" | 1454 NOTREACHED() << "Unable to encode theme image for prs_id=" |
| 1455 << prs_id << " for scale_factor=" << scale_factors_[i]; | 1455 << prs_id << " for scale_factor=" << scale_factors_[i]; |
| 1456 break; | 1456 break; |
| 1457 } | 1457 } |
| 1458 image_memory_[scaled_raw_id] = | 1458 image_memory_[scaled_raw_id] = |
| 1459 base::RefCountedBytes::TakeVector(&bitmap_data); | 1459 base::RefCountedBytes::TakeVector(&bitmap_data); |
| 1460 } | 1460 } |
| 1461 } | 1461 } |
| OLD | NEW |