1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mandoline/ui/aura/aura_init.h"
7 #include "base/i18n/icu_util.h"
8 #include "base/lazy_instance.h"
9 #include "base/path_service.h"
10 #include "components/resource_provider/public/cpp/resource_loader.h"
11 #include "components/view_manager/public/cpp/view.h"
12 #include "mojo/converters/geometry/geometry_type_converters.h"
13 #include "ui/aura/env.h"
14 #include "ui/base/ime/input_method_initializer.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/base/ui_base_paths.h"
22 // Paths resources are loaded from.
23 const char kResourceUIPak
[] = "mandoline_ui.pak";
25 std::set
<std::string
> GetResourcePaths() {
26 std::set
<std::string
> paths
;
27 paths
.insert(kResourceUIPak
);
33 // TODO(sky): the 1.f should be view->viewport_metrics().device_scale_factor,
34 // but that causes clipping problems. No doubt we're not scaling a size
36 AuraInit::AuraInit(mojo::View
* view
, mojo::Shell
* shell
)
37 : ui_init_(view
->viewport_metrics().size_in_pixels
.To
<gfx::Size
>(), 1.f
) {
38 aura::Env::CreateInstance(false);
40 InitializeResources(shell
);
42 ui::InitializeInputMethodForTesting();
45 AuraInit::~AuraInit() {
48 void AuraInit::InitializeResources(mojo::Shell
* shell
) {
49 if (ui::ResourceBundle::HasSharedInstance())
51 resource_provider::ResourceLoader
resource_loader(shell
, GetResourcePaths());
52 if (!resource_loader
.BlockUntilLoaded())
54 CHECK(resource_loader
.loaded());
55 base::i18n::InitializeICUWithFileDescriptor(
56 resource_loader
.GetICUFile().TakePlatformFile(),
57 base::MemoryMappedFile::Region::kWholeFile
);
58 ui::RegisterPathProvider();
59 ui::ResourceBundle::InitSharedInstanceWithPakPath(base::FilePath());
60 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile(
61 resource_loader
.ReleaseFile(kResourceUIPak
),
62 ui::SCALE_FACTOR_100P
);
63 // There is a bunch of static state in gfx::Font, by running this now,
64 // before any other apps load, we ensure all the state is set up.
68 } // namespace mandoline