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

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

Issue 542833002: Fix themes on retina Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/files/file.h" 9 #include "base/files/file.h"
10 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
(...skipping 25 matching lines...) Expand all
36 #include "ui/resources/grit/ui_resources.h" 36 #include "ui/resources/grit/ui_resources.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 = 34; 46 const int kThemePackVersion = 35;
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;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 int idr = kPersistingImagesDesktopAura[i].idr_id; 231 int idr = kPersistingImagesDesktopAura[i].idr_id;
232 int prs_id = kPersistingImagesDesktopAura[i].persistent_id; 232 int prs_id = kPersistingImagesDesktopAura[i].persistent_id;
233 (*lookup_table)[idr] = prs_id; 233 (*lookup_table)[idr] = prs_id;
234 } 234 }
235 #endif 235 #endif
236 } 236 }
237 std::map<int,int>::iterator it = lookup_table->find(idr); 237 std::map<int,int>::iterator it = lookup_table->find(idr);
238 return (it == lookup_table->end()) ? -1 : it->second; 238 return (it == lookup_table->end()) ? -1 : it->second;
239 } 239 }
240 240
241 // Returns the maximum persistent id.
242 int GetMaxPersistentId() {
243 static int max_prs_id = -1;
244 if (max_prs_id == -1) {
245 for (size_t i = 0; i < kPersistingImagesLength; ++i) {
246 if (kPersistingImages[i].persistent_id > max_prs_id)
247 max_prs_id = kPersistingImages[i].persistent_id;
248 }
249 #if defined(USE_ASH) && !defined(OS_CHROMEOS)
250 for (size_t i = 0; i < kPersistingImagesDesktopAuraLength; ++i) {
251 if (kPersistingImagesDesktopAura[i].persistent_id > max_prs_id)
252 max_prs_id = kPersistingImagesDesktopAura[i].persistent_id;
253 }
254 #endif
255 }
256 return max_prs_id;
257 }
258
241 // Returns true if the scales in |input| match those in |expected|. 259 // Returns true if the scales in |input| match those in |expected|.
242 // The order must match as the index is used in determining the raw id. 260 // The order must match as the index is used in determining the raw id.
243 bool InputScalesValid(const base::StringPiece& input, 261 bool InputScalesValid(const base::StringPiece& input,
244 const std::vector<ui::ScaleFactor>& expected) { 262 const std::vector<ui::ScaleFactor>& expected) {
245 size_t scales_size = static_cast<size_t>(input.size() / sizeof(float)); 263 size_t scales_size = static_cast<size_t>(input.size() / sizeof(float));
246 if (scales_size != expected.size()) 264 if (scales_size != expected.size())
247 return false; 265 return false;
248 scoped_ptr<float[]> scales(new float[scales_size]); 266 scoped_ptr<float[]> scales(new float[scales_size]);
249 // Do a memcpy to avoid misaligned memory access. 267 // Do a memcpy to avoid misaligned memory access.
250 memcpy(scales.get(), input.data(), input.size()); 268 memcpy(scales.get(), input.data(), input.size());
(...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 } 1537 }
1520 1538
1521 int BrowserThemePack::GetRawIDByPersistentID( 1539 int BrowserThemePack::GetRawIDByPersistentID(
1522 int prs_id, 1540 int prs_id,
1523 ui::ScaleFactor scale_factor) const { 1541 ui::ScaleFactor scale_factor) const {
1524 if (prs_id < 0) 1542 if (prs_id < 0)
1525 return -1; 1543 return -1;
1526 1544
1527 for (size_t i = 0; i < scale_factors_.size(); ++i) { 1545 for (size_t i = 0; i < scale_factors_.size(); ++i) {
1528 if (scale_factors_[i] == scale_factor) 1546 if (scale_factors_[i] == scale_factor)
1529 return static_cast<int>(kPersistingImagesLength * i) + prs_id; 1547 return ((GetMaxPersistentId() + 1) * i) + prs_id;
1530 } 1548 }
1531 return -1; 1549 return -1;
1532 } 1550 }
1533 1551
1534 bool BrowserThemePack::GetScaleFactorFromManifestKey( 1552 bool BrowserThemePack::GetScaleFactorFromManifestKey(
1535 const std::string& key, 1553 const std::string& key,
1536 ui::ScaleFactor* scale_factor) const { 1554 ui::ScaleFactor* scale_factor) const {
1537 int percent = 0; 1555 int percent = 0;
1538 if (base::StringToInt(key, &percent)) { 1556 if (base::StringToInt(key, &percent)) {
1539 float scale = static_cast<float>(percent) / 100.0f; 1557 float scale = static_cast<float>(percent) / 100.0f;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1612 false, 1630 false,
1613 &bitmap_data)) { 1631 &bitmap_data)) {
1614 NOTREACHED() << "Unable to encode theme image for prs_id=" 1632 NOTREACHED() << "Unable to encode theme image for prs_id="
1615 << prs_id << " for scale_factor=" << scale_factors_[i]; 1633 << prs_id << " for scale_factor=" << scale_factors_[i];
1616 break; 1634 break;
1617 } 1635 }
1618 image_memory_[scaled_raw_id] = 1636 image_memory_[scaled_raw_id] =
1619 base::RefCountedBytes::TakeVector(&bitmap_data); 1637 base::RefCountedBytes::TakeVector(&bitmap_data);
1620 } 1638 }
1621 } 1639 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698