From c81aade568e50a098af8fe39cdc8e07b7099fdb6 Mon Sep 17 00:00:00 2001 From: sadrul Date: Mon, 8 Jun 2015 17:12:43 -0700 Subject: [PATCH] mandoline: Allow running the aura/views UI on android. Setting use_aura=true for android will build the aura UI, and the default UI will be used without it. For aura, fonts do not work correctly in android-views yet though, so the omnibox UI is still non-functional. BUG=488576 Review URL: https://codereview.chromium.org/1164093002 Cr-Commit-Position: refs/heads/master@{#333396} --- mandoline/app/android/BUILD.gn | 12 ++++ mandoline/app/core_services_initialization.cc | 4 +- mandoline/services/core_services/BUILD.gn | 2 +- .../core_services_application_delegate.cc | 4 +- mandoline/ui/BUILD.gn | 4 +- mandoline/ui/aura/BUILD.gn | 7 ++ mandoline/ui/aura/DEPS | 1 + mandoline/ui/aura/aura_init.cc | 80 +++++++++++++--------- mandoline/ui/aura/aura_init.h | 8 ++- mandoline/ui/browser/BUILD.gn | 33 +++++---- mandoline/ui/browser/desktop/desktop_ui.cc | 19 +++-- mandoline/ui/omnibox/BUILD.gn | 9 ++- mandoline/ui/omnibox/omnibox_impl.cc | 2 +- ui/base/BUILD.gn | 36 ++++------ ui/gfx/BUILD.gn | 29 +++++--- ui/gfx/font_fallback_android.cc | 17 +++++ ui/views/widget/native_widget_aura.cc | 2 +- 17 files changed, 174 insertions(+), 95 deletions(-) create mode 100644 ui/gfx/font_fallback_android.cc diff --git a/mandoline/app/android/BUILD.gn b/mandoline/app/android/BUILD.gn index e9a35b807614..be021ea509a0 100644 --- a/mandoline/app/android/BUILD.gn +++ b/mandoline/app/android/BUILD.gn @@ -66,6 +66,18 @@ copy_ex("copy_mandoline_assets") { "$root_out_dir/surfaces_service.mojo", ] + if (use_aura) { + deps += [ + "//mandoline/ui/browser", + "//mandoline/ui/omnibox", + ] + + sources += [ + "$root_out_dir/browser", + "$root_out_dir/omnibox", + ] + } + # Directories can't be specified as sources so pass manually to the script. args = [ "--files=" + rebase_path("$root_out_dir/html_viewer", root_build_dir) ] diff --git a/mandoline/app/core_services_initialization.cc b/mandoline/app/core_services_initialization.cc index 7e9fde84e51e..5dd164019782 100644 --- a/mandoline/app/core_services_initialization.cc +++ b/mandoline/app/core_services_initialization.cc @@ -16,14 +16,14 @@ void InitCoreServicesForContext(mojo::runner::Context* context) { GURL("mojo:core_services"), "Core"); manager->RegisterApplicationPackageAlias(GURL("mojo:filesystem"), GURL("mojo:core_services"), "Files"); -#if !defined(OS_ANDROID) +#if defined(USE_AURA) manager->RegisterApplicationPackageAlias(GURL("mojo:view_manager"), GURL("mojo:core_services"), "Surfaces"); #endif manager->RegisterApplicationPackageAlias( GURL("mojo:network_service"), GURL("mojo:core_services"), "Network"); -#if !defined(OS_ANDROID) +#if defined(USE_AURA) manager->RegisterApplicationPackageAlias( GURL("mojo:omnibox"), GURL("mojo:core_services"), "Core"); #endif diff --git a/mandoline/services/core_services/BUILD.gn b/mandoline/services/core_services/BUILD.gn index 92899364ca28..bec66ad5d12a 100644 --- a/mandoline/services/core_services/BUILD.gn +++ b/mandoline/services/core_services/BUILD.gn @@ -75,7 +75,7 @@ source_set("sources") { "//mojo/services/tracing:lib", ] - if (!is_android) { + if (use_aura) { deps += [ "//components/view_manager/public/cpp", "//mandoline/ui/omnibox:lib", diff --git a/mandoline/services/core_services/core_services_application_delegate.cc b/mandoline/services/core_services/core_services_application_delegate.cc index 3867c55ea081..b31fff8bb8c7 100644 --- a/mandoline/services/core_services/core_services_application_delegate.cc +++ b/mandoline/services/core_services/core_services_application_delegate.cc @@ -21,7 +21,7 @@ #include "mojo/services/tracing/tracing_app.h" #include "url/gurl.h" -#if !defined(OS_ANDROID) +#if defined(USE_AURA) #include "mandoline/ui/omnibox/omnibox_impl.h" #endif @@ -129,7 +129,7 @@ void CoreServicesApplicationDelegate::StartApplication( delegate.reset(new filesystem::FileSystemApp); else if (url == "mojo://network_service/") delegate.reset(new NetworkServiceDelegate); -#if !defined(OS_ANDROID) +#if defined(USE_AURA) else if (url == "mojo://omnibox/") delegate.reset(new mandoline::OmniboxImpl); #endif diff --git a/mandoline/ui/BUILD.gn b/mandoline/ui/BUILD.gn index 572918fade7c..4cf27209d0e6 100644 --- a/mandoline/ui/BUILD.gn +++ b/mandoline/ui/BUILD.gn @@ -2,14 +2,14 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import("//build/config/ui.gni") import("//third_party/mojo/src/mojo/public/mojo.gni") group("ui") { deps = [ "browser", ] - - if (!is_android) { + if (use_aura) { deps += [ "omnibox" ] } } diff --git a/mandoline/ui/aura/BUILD.gn b/mandoline/ui/aura/BUILD.gn index 1bccf3cf0ffb..a25c02bf47ec 100644 --- a/mandoline/ui/aura/BUILD.gn +++ b/mandoline/ui/aura/BUILD.gn @@ -49,4 +49,11 @@ source_set("aura") { "//ui/resources:ui_test_pak", "//ui/views", ] + + if (is_android) { + deps += [ + "//components/resource_provider/public/cpp", + "//components/resource_provider/public/interfaces", + ] + } } diff --git a/mandoline/ui/aura/DEPS b/mandoline/ui/aura/DEPS index d7c4cb69b1df..91015f8e09f8 100644 --- a/mandoline/ui/aura/DEPS +++ b/mandoline/ui/aura/DEPS @@ -2,6 +2,7 @@ include_rules = [ "+cc", "-cc/blink", "+components/gpu", + "+components/resource_provider", "+components/view_manager", "+mojo/application/public", "+mojo/cc", diff --git a/mandoline/ui/aura/aura_init.cc b/mandoline/ui/aura/aura_init.cc index f14a477a98e1..751062164d6f 100644 --- a/mandoline/ui/aura/aura_init.cc +++ b/mandoline/ui/aura/aura_init.cc @@ -12,51 +12,69 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/base/ui_base_paths.h" -namespace mandoline { -namespace { - -// Used to ensure we only init once. -class Setup { - public: - Setup() { - base::i18n::InitializeICU(); - - ui::RegisterPathProvider(); +#if defined(OS_ANDROID) +#include "components/resource_provider/public/cpp/resource_loader.h" +#endif - base::FilePath ui_test_pak_path; - CHECK(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); - ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); - - // There is a bunch of static state in gfx::Font, by running this now, - // before any other apps load, we ensure all the state is set up. - gfx::Font(); - } +namespace mandoline { - ~Setup() { - } +#if defined(OS_ANDROID) +namespace { - private: - DISALLOW_COPY_AND_ASSIGN(Setup); -}; +// Paths resources are loaded from. +const char kResourceIcudtl[] = "icudtl.dat"; +const char kResourceUIPak[] = "ui_test.pak"; -static base::LazyInstance::Leaky setup = LAZY_INSTANCE_INITIALIZER; +std::set GetResourcePaths() { + std::set paths; + paths.insert(kResourceIcudtl); + paths.insert(kResourceUIPak); + return paths; +} } // namespace +#endif // defined(OS_ANDROID) -void InitViews() { - setup.Get(); -} - -AuraInit::AuraInit() { +AuraInit::AuraInit(mojo::Shell* shell) { aura::Env::CreateInstance(false); screen_.reset(ScreenMojo::Create()); gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); - - InitViews(); + InitializeResources(shell); } AuraInit::~AuraInit() { } +void AuraInit::InitializeResources(mojo::Shell* shell) { + if (ui::ResourceBundle::HasSharedInstance()) + return; +#if defined(OS_ANDROID) + resource_provider::ResourceLoader resource_loader(shell, GetResourcePaths()); + if (!resource_loader.BlockUntilLoaded()) + return; + CHECK(resource_loader.loaded()); + base::i18n::InitializeICUWithFileDescriptor( + resource_loader.ReleaseFile(kResourceIcudtl).TakePlatformFile(), + base::MemoryMappedFile::Region::kWholeFile); + ui::RegisterPathProvider(); + ui::ResourceBundle::InitSharedInstanceWithPakPath(base::FilePath()); + ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( + resource_loader.ReleaseFile(kResourceUIPak), + ui::SCALE_FACTOR_100P); +#else + base::i18n::InitializeICU(); + + ui::RegisterPathProvider(); + + base::FilePath ui_test_pak_path; + CHECK(PathService::Get(ui::UI_TEST_PAK, &ui_test_pak_path)); + ui::ResourceBundle::InitSharedInstanceWithPakPath(ui_test_pak_path); +#endif + + // There is a bunch of static state in gfx::Font, by running this now, + // before any other apps load, we ensure all the state is set up. + gfx::Font(); +} + } // namespace mandoline diff --git a/mandoline/ui/aura/aura_init.h b/mandoline/ui/aura/aura_init.h index abe833fa6ade..98f065b88472 100644 --- a/mandoline/ui/aura/aura_init.h +++ b/mandoline/ui/aura/aura_init.h @@ -7,6 +7,10 @@ #include "base/memory/scoped_ptr.h" +namespace mojo { +class Shell; +} + namespace mandoline { class ScreenMojo; @@ -14,10 +18,12 @@ class ScreenMojo; // Sets up necessary state for aura when run with the viewmanager. class AuraInit { public: - AuraInit(); + explicit AuraInit(mojo::Shell* shell); ~AuraInit(); private: + void InitializeResources(mojo::Shell* shell); + scoped_ptr screen_; DISALLOW_COPY_AND_ASSIGN(AuraInit); diff --git a/mandoline/ui/browser/BUILD.gn b/mandoline/ui/browser/BUILD.gn index b03702317e17..0f2793cb7671 100644 --- a/mandoline/ui/browser/BUILD.gn +++ b/mandoline/ui/browser/BUILD.gn @@ -2,10 +2,11 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -import("//third_party/mojo/src/mojo/public/mojo_application.gni") +import("//build/config/ui.gni") +import("//mojo/mojo_application_package.gni") import("//third_party/mojo/src/mojo/public/tools/bindings/mojom.gni") -mojo_native_application("browser") { +mojo_application_package("browser") { sources = [ "main.cc", ] @@ -15,6 +16,10 @@ mojo_native_application("browser") { "//mandoline/services/navigation/public/interfaces", "//mojo/application/public/cpp", ] + resources = [ + "$root_out_dir/icudtl.dat", + "$root_out_dir/ui_test.pak", + ] } source_set("lib") { @@ -27,18 +32,6 @@ source_set("lib") { "navigator_host_impl.h", ] - if (is_android) { - sources += [ - "android/android_ui.cc", - "android/android_ui.h", - ] - } else { - sources += [ - "desktop/desktop_ui.cc", - "desktop/desktop_ui.h", - ] - } - deps = [ ":interfaces", "//base", @@ -53,8 +46,18 @@ source_set("lib") { "//ui/mojo/events:interfaces", ] - if (!is_android) { + if (use_aura) { + sources += [ + "desktop/desktop_ui.cc", + "desktop/desktop_ui.h", + ] deps += [ "//mandoline/ui/aura" ] + } else { + assert(is_android) + sources += [ + "android/android_ui.cc", + "android/android_ui.h", + ] } } diff --git a/mandoline/ui/browser/desktop/desktop_ui.cc b/mandoline/ui/browser/desktop/desktop_ui.cc index b454f213e487..6200f96382ae 100644 --- a/mandoline/ui/browser/desktop/desktop_ui.cc +++ b/mandoline/ui/browser/desktop/desktop_ui.cc @@ -21,10 +21,10 @@ namespace mandoline { // DesktopUI, public: DesktopUI::DesktopUI(Browser* browser, mojo::ApplicationImpl* application_impl) - : browser_(browser), + : aura_init_(application_impl->shell()), + browser_(browser), application_impl_(application_impl), - omnibox_launcher_( - new views::LabelButton(this, base::ASCIIToUTF16("Open Omnibox"))), + omnibox_launcher_(nullptr), root_(nullptr), client_binding_(browser) { } @@ -40,7 +40,11 @@ void DesktopUI::Init(mojo::View* root) { views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; widget_delegate->GetContentsView()->set_background( views::Background::CreateSolidBackground(0xFFDDDDDD)); +#if !defined(OS_ANDROID) + omnibox_launcher_ = + new views::LabelButton(this, base::ASCIIToUTF16("Open Omnibox")); widget_delegate->GetContentsView()->AddChildView(omnibox_launcher_); +#endif widget_delegate->GetContentsView()->SetLayoutManager(this); views::Widget* widget = new views::Widget; @@ -56,7 +60,10 @@ void DesktopUI::Init(mojo::View* root) { } void DesktopUI::OnURLChanged() { - omnibox_launcher_->SetText(base::UTF8ToUTF16(browser_->current_url().spec())); + // TODO(sad): Remove the conditional below once UI fonts are fixed on android. + if (omnibox_launcher_) + omnibox_launcher_->SetText( + base::UTF8ToUTF16(browser_->current_url().spec())); } //////////////////////////////////////////////////////////////////////////////// @@ -69,7 +76,9 @@ gfx::Size DesktopUI::GetPreferredSize(const views::View* view) const { void DesktopUI::Layout(views::View* host) { gfx::Rect omnibox_launcher_bounds = host->bounds(); omnibox_launcher_bounds.Inset(10, 10, 10, host->bounds().height() - 40); - omnibox_launcher_->SetBoundsRect(omnibox_launcher_bounds); + // TODO(sad): Remove the conditional below once UI fonts are fixed on android. + if (omnibox_launcher_) + omnibox_launcher_->SetBoundsRect(omnibox_launcher_bounds); mojo::Rect content_bounds_mojo; content_bounds_mojo.x = omnibox_launcher_bounds.x(); diff --git a/mandoline/ui/omnibox/BUILD.gn b/mandoline/ui/omnibox/BUILD.gn index c7f8c39fcd08..dd81468e4b9b 100644 --- a/mandoline/ui/omnibox/BUILD.gn +++ b/mandoline/ui/omnibox/BUILD.gn @@ -2,10 +2,10 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -import("//third_party/mojo/src/mojo/public/mojo_application.gni") +import("//mojo/mojo_application_package.gni") import("//third_party/mojo/src/mojo/public/tools/bindings/mojom.gni") -mojo_native_application("omnibox") { +mojo_application_package("omnibox") { sources = [ "main.cc", ] @@ -15,6 +15,11 @@ mojo_native_application("omnibox") { "//mandoline/services/navigation/public/interfaces", "//mojo/application/public/cpp", ] + + resources = [ + "$root_out_dir/icudtl.dat", + "$root_out_dir/ui_test.pak", + ] } source_set("lib") { diff --git a/mandoline/ui/omnibox/omnibox_impl.cc b/mandoline/ui/omnibox/omnibox_impl.cc index 756ab9daeca2..edeef04d32be 100644 --- a/mandoline/ui/omnibox/omnibox_impl.cc +++ b/mandoline/ui/omnibox/omnibox_impl.cc @@ -55,7 +55,7 @@ void OmniboxImpl::OnEmbed(mojo::View* root, mojo::InterfaceRequest services, mojo::ServiceProviderPtr exposed_services) { if (!aura_init_.get()) { - aura_init_.reset(new AuraInit); + aura_init_.reset(new AuraInit(app_impl_->shell())); edit_ = new views::Textfield; edit_->set_controller(this); } diff --git a/ui/base/BUILD.gn b/ui/base/BUILD.gn index e869be236cc3..3d39a7559f2e 100644 --- a/ui/base/BUILD.gn +++ b/ui/base/BUILD.gn @@ -402,7 +402,7 @@ component("base") { sources -= [ "idle/idle_linux.cc" ] } - if (is_chromeos || (use_aura && is_linux && !use_x11)) { + if (is_chromeos || (use_aura && ((is_linux && !use_x11) || is_android))) { sources += [ "dragdrop/os_exchange_data_provider_aura.cc", "dragdrop/os_exchange_data_provider_aura.h", @@ -498,16 +498,11 @@ component("base") { ] } - if (!toolkit_views) { + if (!toolkit_views && !use_aura) { sources -= [ "dragdrop/drag_drop_types.h", "dragdrop/drop_target_event.cc", "dragdrop/drop_target_event.h", - ] - } - - if (!toolkit_views && !use_aura) { - sources -= [ "dragdrop/os_exchange_data.cc", "dragdrop/os_exchange_data.h", "nine_image_painter_factory.cc", @@ -516,7 +511,18 @@ component("base") { } if (is_android) { + deps += [ + "//cc", + ":ui_base_jni_headers", + "//ui/android:ui_java", + ] + + libs += [ "jnigraphics" ] + } + + if (is_android && !use_aura) { sources -= [ + "cursor/cursor_android.cc", "cursor/image_cursors.cc", "cursor/image_cursors.h", "default_theme_provider.cc", @@ -529,26 +535,14 @@ component("base") { "touch/touch_editing_controller.cc", "ui_base_types.cc", ] - - deps += [ - "//cc", - ":ui_base_jni_headers", - "//ui/android:ui_java", - ] - - libs += [ "jnigraphics" ] - } - - if (is_android && !use_aura) { - sources -= [ "cursor/cursor_android.cc" ] } # Aura clipboard. if (use_aura) { if (use_x11) { sources += [ "clipboard/clipboard_aurax11.cc" ] - } else if (!is_win) { - # This file is used for all non-X11, non-Windows aura Builds. + } else if (!is_win && !is_android) { + # This file is used for all non-X11, non-Windows, non-Android aura Builds. sources += [ "clipboard/clipboard_aura.cc" ] } } diff --git a/ui/gfx/BUILD.gn b/ui/gfx/BUILD.gn index 5d7973cd310e..f6f27bc4731c 100644 --- a/ui/gfx/BUILD.gn +++ b/ui/gfx/BUILD.gn @@ -251,9 +251,7 @@ component("gfx") { ] # Text rendering conditions (complicated so separated out). - if (is_android || is_ios) { - # We don't support RenderText on these platforms. - } else { + if (use_aura || is_mac) { # Mac doesn't use RenderTextHarfBuzz by default yet. sources += [ "harfbuzz_font_skia.cc", @@ -266,6 +264,12 @@ component("gfx") { "render_text_mac.h", "text_utils_skia.cc", ] + } else { + # We don't support RenderText on these platforms. + } + + if (is_android && use_aura) { + sources -= [ "text_utils_android.cc" ] } # iOS. @@ -280,16 +284,19 @@ component("gfx") { # Android. if (is_android) { - sources -= [ - "animation/throb_animation.cc", - "canvas_skia.cc", - "selection_model.cc", - ] - if (use_aura) { - sources -= [ "screen_android.cc" ] + sources -= [ + "canvas_notimplemented.cc", + "screen_android.cc", + ] + sources += [ "font_fallback_android.cc" ] } else { - sources -= [ "path.cc" ] + sources -= [ + "animation/throb_animation.cc", + "canvas_skia.cc", + "path.cc", + "selection_model.cc", + ] } if (!is_debug) { diff --git a/ui/gfx/font_fallback_android.cc b/ui/gfx/font_fallback_android.cc new file mode 100644 index 000000000000..37f9b697320d --- /dev/null +++ b/ui/gfx/font_fallback_android.cc @@ -0,0 +1,17 @@ +// Copyright 2015 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/gfx/font_fallback.h" + +#include +#include + +namespace gfx { + +std::vector GetFallbackFontFamilies( + const std::string& font_family) { + return std::vector(); +} + +} // namespace gfx diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc index 92ff22acd056..b4e7fc414d70 100644 --- a/ui/views/widget/native_widget_aura.cc +++ b/ui/views/widget/native_widget_aura.cc @@ -705,7 +705,7 @@ void NativeWidgetAura::SetVisibilityAnimationTransition( } ui::NativeTheme* NativeWidgetAura::GetNativeTheme() const { -#if !defined(OS_CHROMEOS) +#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) return DesktopWindowTreeHost::GetNativeTheme(window_); #else return ui::NativeThemeAura::instance(); -- 2.11.4.GIT