summaryrefslogtreecommitdiffstats
path: root/ui/base/resource/resource_bundle_aurax11.cc
blob: bdb6fcc3641ff95e518af9245864ca81f1e56353 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/base/resource/resource_bundle.h"

#include "base/command_line.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "ui/base/layout.h"
#include "ui/base/resource/resource_handle.h"
#include "ui/base/ui_base_paths.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/display.h"
#include "ui/gfx/image/image.h"

namespace {

FilePath GetResourcesPakFilePath(const std::string& pak_name) {
  FilePath path;
  if (PathService::Get(base::DIR_MODULE, &path))
    return path.AppendASCII(pak_name.c_str());

  // Return just the name of the pack file.
  return FilePath(pak_name.c_str());
}

bool ShouldLoad2xResources() {
  return gfx::Display::GetForcedDeviceScaleFactor() > 1.0f ||
      CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoad2xResources);
}

}  // namespace

namespace ui {

void ResourceBundle::LoadCommonResources() {
  // Always load the 1x data pack first as the 2x data pack contains both 1x and
  // 2x images. The 1x data pack only has 1x images, thus passes in an accurate
  // scale factor to gfx::ImageSkia::AddRepresentation.

  AddDataPackFromPath(GetResourcesPakFilePath("chrome.pak"),
                      SCALE_FACTOR_100P);

  if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) {
    // 1x touch
    AddDataPackFromPath(GetResourcesPakFilePath("theme_resources_touch_1x.pak"),
                        SCALE_FACTOR_100P);
    AddDataPackFromPath(GetResourcesPakFilePath("ui_resources_touch.pak"),
                        SCALE_FACTOR_100P);
    if (ShouldLoad2xResources()) {
      // 2x touch
      AddDataPackFromPath(
          GetResourcesPakFilePath("theme_resources_touch_2x.pak"),
          SCALE_FACTOR_200P);
      AddDataPackFromPath(GetResourcesPakFilePath("ui_resources_touch_2x.pak"),
                          SCALE_FACTOR_200P);
    }
  } else {
    // 1x non touch
    AddDataPackFromPath(GetResourcesPakFilePath("theme_resources_standard.pak"),
                        SCALE_FACTOR_100P);
    AddDataPackFromPath(GetResourcesPakFilePath("ui_resources_standard.pak"),
                        SCALE_FACTOR_100P);
    if (ShouldLoad2xResources()) {
      // 2x non touch
      AddDataPackFromPath(GetResourcesPakFilePath("theme_resources_2x.pak"),
                          SCALE_FACTOR_200P);
      AddDataPackFromPath(GetResourcesPakFilePath("ui_resources_2x.pak"),
                          SCALE_FACTOR_200P);
    }
  }
}

gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id, ImageRTL rtl) {
  // Flipped image is not used on ChromeOS.
  DCHECK_EQ(rtl, RTL_DISABLED);
  return GetImageNamed(resource_id);
}

}  // namespace ui