diff options
author | sky <sky@chromium.org> | 2015-06-18 17:55:20 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-19 00:56:49 +0000 |
commit | f760367972c3f3fb5143e7cea5bd6fc29ec3a0a9 (patch) | |
tree | 27193718b69445158806ae2bc3086cec8f2e3c76 /mandoline | |
parent | 0e90449a7c9bd8f051fce4988a8cccd6c1c64661 (diff) | |
download | chromium_src-f760367972c3f3fb5143e7cea5bd6fc29ec3a0a9.zip chromium_src-f760367972c3f3fb5143e7cea5bd6fc29ec3a0a9.tar.gz chromium_src-f760367972c3f3fb5143e7cea5bd6fc29ec3a0a9.tar.bz2 |
Fixes crash on android when clicking on non-blink
The crash happened because we weren't setting a
GestureConfiguration. Without setting one we try to use the system
one, which requires JNI.
HTMLViewer has code for doing this. There was some overlap with
existing code so I refactored and combined.
BUG=501387
TEST=none
R=fsamuel@chromium.org
Review URL: https://codereview.chromium.org/1193733002
Cr-Commit-Position: refs/heads/master@{#335184}
Diffstat (limited to 'mandoline')
-rw-r--r-- | mandoline/ui/aura/BUILD.gn | 3 | ||||
-rw-r--r-- | mandoline/ui/aura/DEPS | 1 | ||||
-rw-r--r-- | mandoline/ui/aura/aura_init.cc | 11 | ||||
-rw-r--r-- | mandoline/ui/aura/aura_init.h | 9 | ||||
-rw-r--r-- | mandoline/ui/aura/screen_mojo.cc | 73 | ||||
-rw-r--r-- | mandoline/ui/aura/screen_mojo.h | 49 | ||||
-rw-r--r-- | mandoline/ui/browser/browser.cc | 33 | ||||
-rw-r--r-- | mandoline/ui/browser/browser.h | 6 | ||||
-rw-r--r-- | mandoline/ui/browser/browser_manager.cc | 69 | ||||
-rw-r--r-- | mandoline/ui/browser/browser_manager.h | 13 | ||||
-rw-r--r-- | mandoline/ui/omnibox/omnibox_impl.cc | 2 |
11 files changed, 119 insertions, 150 deletions
diff --git a/mandoline/ui/aura/BUILD.gn b/mandoline/ui/aura/BUILD.gn index 275fce86..7cf859c 100644 --- a/mandoline/ui/aura/BUILD.gn +++ b/mandoline/ui/aura/BUILD.gn @@ -11,8 +11,6 @@ source_set("aura") { "input_method_mandoline.h", "native_widget_view_manager.cc", "native_widget_view_manager.h", - "screen_mojo.cc", - "screen_mojo.h", "surface_binding.cc", "surface_binding.h", "surface_context_factory.cc", @@ -47,6 +45,7 @@ source_set("aura") { "//ui/events", "//ui/events:events_base", "//ui/gl", + "//ui/mojo/init", "//ui/resources:ui_test_pak", "//ui/views", ] diff --git a/mandoline/ui/aura/DEPS b/mandoline/ui/aura/DEPS index 91015f8..e7b7185 100644 --- a/mandoline/ui/aura/DEPS +++ b/mandoline/ui/aura/DEPS @@ -15,6 +15,7 @@ include_rules = [ "+ui/events", "+ui/gfx", "+ui/gl", + "+ui/mojo/init", "+ui/views", "+ui/wm", ] diff --git a/mandoline/ui/aura/aura_init.cc b/mandoline/ui/aura/aura_init.cc index 946a118..9f865f9 100644 --- a/mandoline/ui/aura/aura_init.cc +++ b/mandoline/ui/aura/aura_init.cc @@ -7,7 +7,8 @@ #include "base/i18n/icu_util.h" #include "base/lazy_instance.h" #include "base/path_service.h" -#include "mandoline/ui/aura/screen_mojo.h" +#include "components/view_manager/public/cpp/view.h" +#include "mojo/converters/geometry/geometry_type_converters.h" #include "ui/aura/env.h" #include "ui/base/ime/input_method_initializer.h" #include "ui/base/resource/resource_bundle.h" @@ -36,11 +37,13 @@ std::set<std::string> GetResourcePaths() { } // namespace #endif // defined(OS_ANDROID) -AuraInit::AuraInit(mojo::Shell* shell) { +// TODO(sky): the 1.f should be view->viewport_metrics().device_scale_factor, +// but that causes clipping problems. No doubt we're not scaling a size +// correctly. +AuraInit::AuraInit(mojo::View* view, mojo::Shell* shell) + : ui_init_(view->viewport_metrics().size_in_pixels.To<gfx::Size>(), 1.f) { aura::Env::CreateInstance(false); - screen_.reset(ScreenMojo::Create()); - gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); InitializeResources(shell); ui::InitializeInputMethodForTesting(); diff --git a/mandoline/ui/aura/aura_init.h b/mandoline/ui/aura/aura_init.h index 98f065b..11388a6 100644 --- a/mandoline/ui/aura/aura_init.h +++ b/mandoline/ui/aura/aura_init.h @@ -5,26 +5,25 @@ #ifndef MANDOLINE_UI_AURA_AURA_INIT_H_ #define MANDOLINE_UI_AURA_AURA_INIT_H_ -#include "base/memory/scoped_ptr.h" +#include "ui/mojo/init/ui_init.h" namespace mojo { class Shell; +class View; } namespace mandoline { -class ScreenMojo; - // Sets up necessary state for aura when run with the viewmanager. class AuraInit { public: - explicit AuraInit(mojo::Shell* shell); + AuraInit(mojo::View* root, mojo::Shell* shell); ~AuraInit(); private: void InitializeResources(mojo::Shell* shell); - scoped_ptr<ScreenMojo> screen_; + ui::mojo::UIInit ui_init_; DISALLOW_COPY_AND_ASSIGN(AuraInit); }; diff --git a/mandoline/ui/aura/screen_mojo.cc b/mandoline/ui/aura/screen_mojo.cc deleted file mode 100644 index b15a68e..0000000 --- a/mandoline/ui/aura/screen_mojo.cc +++ /dev/null @@ -1,73 +0,0 @@ -// 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 "mandoline/ui/aura/screen_mojo.h" - -#include "ui/gfx/geometry/rect_conversions.h" -#include "ui/gfx/native_widget_types.h" - -namespace mandoline { - -// static -ScreenMojo* ScreenMojo::Create() { - // TODO(beng): this is bogus & should be derived from the native viewport's - // client area. https://crbug.com/487340 - return new ScreenMojo(gfx::Rect(1280, 800)); -} - -ScreenMojo::~ScreenMojo() { -} - -gfx::Point ScreenMojo::GetCursorScreenPoint() { - NOTIMPLEMENTED(); - return gfx::Point(); -} - -gfx::NativeWindow ScreenMojo::GetWindowUnderCursor() { - return GetWindowAtScreenPoint(GetCursorScreenPoint()); -} - -gfx::NativeWindow ScreenMojo::GetWindowAtScreenPoint(const gfx::Point& point) { - NOTIMPLEMENTED(); - return NULL; -} - -int ScreenMojo::GetNumDisplays() const { - return 1; -} - -std::vector<gfx::Display> ScreenMojo::GetAllDisplays() const { - return std::vector<gfx::Display>(1, display_); -} - -gfx::Display ScreenMojo::GetDisplayNearestWindow( - gfx::NativeWindow window) const { - return display_; -} - -gfx::Display ScreenMojo::GetDisplayNearestPoint(const gfx::Point& point) const { - return display_; -} - -gfx::Display ScreenMojo::GetDisplayMatching(const gfx::Rect& match_rect) const { - return display_; -} - -gfx::Display ScreenMojo::GetPrimaryDisplay() const { - return display_; -} - -void ScreenMojo::AddObserver(gfx::DisplayObserver* observer) { -} - -void ScreenMojo::RemoveObserver(gfx::DisplayObserver* observer) { -} - -ScreenMojo::ScreenMojo(const gfx::Rect& screen_bounds) { - static int64 synthesized_display_id = 2000; - display_.set_id(synthesized_display_id++); - display_.SetScaleAndBounds(1.0f, screen_bounds); -} - -} // namespace mandoline diff --git a/mandoline/ui/aura/screen_mojo.h b/mandoline/ui/aura/screen_mojo.h deleted file mode 100644 index 964c21a..0000000 --- a/mandoline/ui/aura/screen_mojo.h +++ /dev/null @@ -1,49 +0,0 @@ -// 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. - -#ifndef MANDOLINE_UI_AURA_SCREEN_MOJO_H_ -#define MANDOLINE_UI_AURA_SCREEN_MOJO_H_ - -#include "base/macros.h" -#include "ui/gfx/display.h" -#include "ui/gfx/screen.h" - -namespace gfx { -class Rect; -class Transform; -} - -namespace mandoline { - -// A minimal implementation of gfx::Screen for mojo. -class ScreenMojo : public gfx::Screen { - public: - static ScreenMojo* Create(); - ~ScreenMojo() override; - - protected: - // gfx::Screen overrides: - gfx::Point GetCursorScreenPoint() override; - gfx::NativeWindow GetWindowUnderCursor() override; - gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override; - int GetNumDisplays() const override; - std::vector<gfx::Display> GetAllDisplays() const override; - gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override; - gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override; - gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override; - gfx::Display GetPrimaryDisplay() const override; - void AddObserver(gfx::DisplayObserver* observer) override; - void RemoveObserver(gfx::DisplayObserver* observer) override; - - private: - explicit ScreenMojo(const gfx::Rect& screen_bounds); - - gfx::Display display_; - - DISALLOW_COPY_AND_ASSIGN(ScreenMojo); -}; - -} // namespace mandoline - -#endif // MANDOLINE_UI_AURA_SCREEN_MOJO_H_ diff --git a/mandoline/ui/browser/browser.cc b/mandoline/ui/browser/browser.cc index eb56630..96424fd 100644 --- a/mandoline/ui/browser/browser.cc +++ b/mandoline/ui/browser/browser.cc @@ -69,19 +69,8 @@ void Browser::ReplaceContentWithRequest(mojo::URLRequestPtr request) { Embed(request.Pass()); } -void Browser::OnEmbed(mojo::View* root) { - // Browser does not support being embedded more than once. - CHECK(!root_); - - // Make it so we get OnWillEmbed() for any Embed()s done by other apps we - // Embed(). - root->view_manager()->SetEmbedRoot(); - - // TODO(beng): still unhappy with the fact that both this class & the UI class - // know so much about these views. Figure out how to shift more to - // the UI class. - root_ = root; - content_ = root->view_manager()->CreateView(); +void Browser::OnDevicePixelRatioAvailable() { + content_ = root_->view_manager()->CreateView(); ui_->Init(root_); view_manager_init_.view_manager_root()->SetViewportSize( @@ -103,6 +92,24 @@ void Browser::OnEmbed(mojo::View* root) { } } +void Browser::OnEmbed(mojo::View* root) { + // Browser does not support being embedded more than once. + CHECK(!root_); + + // Make it so we get OnWillEmbed() for any Embed()s done by other apps we + // Embed(). + root->view_manager()->SetEmbedRoot(); + + // TODO(beng): still unhappy with the fact that both this class & the UI class + // know so much about these views. Figure out how to shift more to + // the UI class. + root_ = root; + + if (!browser_manager_->InitUIIfNecessary(this, root_)) + return; // We'll be called back from OnDevicePixelRatioAvailable(). + OnDevicePixelRatioAvailable(); +} + void Browser::OnEmbedForDescendant(mojo::View* view, mojo::URLRequestPtr request, mojo::ViewManagerClientPtr* client) { diff --git a/mandoline/ui/browser/browser.h b/mandoline/ui/browser/browser.h index fa6c48d..e7d2c55 100644 --- a/mandoline/ui/browser/browser.h +++ b/mandoline/ui/browser/browser.h @@ -47,6 +47,12 @@ class Browser : public mojo::ViewManagerDelegate, const GURL& current_url() const { return current_url_; } + // Called once a valid device_pixel_ratio is determined. We gate construction + // of the UI until the device_pixel_ratio is available as it's necessary to + // properly setup the ui. + // TODO(sky): remove this. Only here until we move to viewmanager. + void OnDevicePixelRatioAvailable(); + private: // Overridden from mojo::ViewManagerDelegate: void OnEmbed(mojo::View* root) override; diff --git a/mandoline/ui/browser/browser_manager.cc b/mandoline/ui/browser/browser_manager.cc index 8b4089d..7d828fc 100644 --- a/mandoline/ui/browser/browser_manager.cc +++ b/mandoline/ui/browser/browser_manager.cc @@ -4,10 +4,52 @@ #include "mandoline/ui/browser/browser_manager.h" +#include "components/view_manager/public/cpp/view.h" +#include "components/view_manager/public/cpp/view_observer.h" #include "mandoline/ui/browser/browser.h" namespace mandoline { +// TODO(sky): make ViewManager not do anything until device_pixel_ratio is +// determined. At which point this can be nuked. +class BrowserManager::DevicePixelRatioWaiter : mojo::ViewObserver { + public: + DevicePixelRatioWaiter(BrowserManager* manager, + Browser* browser, + mojo::View* view) + : manager_(manager), browser_(browser), view_(view) { + view_->AddObserver(this); + } + ~DevicePixelRatioWaiter() override { RemoveObserver(); } + + private: + void RemoveObserver() { + if (!view_) + return; + view_->RemoveObserver(this); + view_ = nullptr; + } + + // mojo::ViewObserver: + void OnViewViewportMetricsChanged( + mojo::View* view, + const mojo::ViewportMetrics& old_metrics, + const mojo::ViewportMetrics& new_metrics) override { + if (new_metrics.device_pixel_ratio == 0) + return; + + RemoveObserver(); + manager_->OnDevicePixelRatioAvailable(browser_, view); + } + void OnViewDestroyed(mojo::View* view) override { RemoveObserver(); } + + BrowserManager* manager_; + Browser* browser_; + mojo::View* view_; + + DISALLOW_COPY_AND_ASSIGN(DevicePixelRatioWaiter); +}; + BrowserManager::BrowserManager() : app_(nullptr) { } @@ -31,6 +73,30 @@ void BrowserManager::BrowserClosed(Browser* browser) { app_->Terminate(); } +bool BrowserManager::InitUIIfNecessary(Browser* browser, mojo::View* view) { + if (view->viewport_metrics().device_pixel_ratio > 0) { +#if defined(USE_AURA) + if (!aura_init_) + aura_init_.reset(new AuraInit(view, app_->shell())); +#endif + return true; + } + DCHECK(!device_pixel_ratio_waiter_.get()); + device_pixel_ratio_waiter_.reset( + new DevicePixelRatioWaiter(this, browser, view)); + return false; +} + +void BrowserManager::OnDevicePixelRatioAvailable(Browser* browser, + mojo::View* view) { + device_pixel_ratio_waiter_.reset(); +#if defined(USE_AURA) + DCHECK(!aura_init_.get()); + aura_init_.reset(new AuraInit(view, app_->shell())); +#endif + browser->OnDevicePixelRatioAvailable(); +} + void BrowserManager::LaunchURL(const mojo::String& url) { DCHECK(!browsers_.empty()); mojo::URLRequestPtr request(mojo::URLRequest::New()); @@ -42,9 +108,6 @@ void BrowserManager::LaunchURL(const mojo::String& url) { void BrowserManager::Initialize(mojo::ApplicationImpl* app) { app_ = app; -#if defined(USE_AURA) - aura_init_.reset(new AuraInit(app->shell())); -#endif CreateBrowser(); } diff --git a/mandoline/ui/browser/browser_manager.h b/mandoline/ui/browser/browser_manager.h index 341f5a4..cb2927b 100644 --- a/mandoline/ui/browser/browser_manager.h +++ b/mandoline/ui/browser/browser_manager.h @@ -18,6 +18,10 @@ #include "mandoline/ui/aura/aura_init.h" #endif +namespace mojo { +class View; +} + namespace mandoline { class Browser; @@ -36,7 +40,13 @@ class BrowserManager : public mojo::ApplicationDelegate, // Invoked by |browser| when it has closed. void BrowserClosed(Browser* browser); + bool InitUIIfNecessary(Browser* browser, mojo::View* view); + private: + class DevicePixelRatioWaiter; + + void OnDevicePixelRatioAvailable(Browser* browser, mojo::View* view); + // Overridden from LaunchHandler: void LaunchURL(const mojo::String& url) override; @@ -50,12 +60,15 @@ class BrowserManager : public mojo::ApplicationDelegate, mojo::InterfaceRequest<LaunchHandler> request) override; mojo::ApplicationImpl* app_; + // TODO(sky): This should be held in the ui classes, not here. #if defined(USE_AURA) scoped_ptr<AuraInit> aura_init_; #endif mojo::WeakBindingSet<LaunchHandler> launch_handler_bindings_; std::set<Browser*> browsers_; + scoped_ptr<DevicePixelRatioWaiter> device_pixel_ratio_waiter_; + DISALLOW_COPY_AND_ASSIGN(BrowserManager); }; diff --git a/mandoline/ui/omnibox/omnibox_impl.cc b/mandoline/ui/omnibox/omnibox_impl.cc index 0509693..eba94bb 100644 --- a/mandoline/ui/omnibox/omnibox_impl.cc +++ b/mandoline/ui/omnibox/omnibox_impl.cc @@ -53,7 +53,7 @@ bool OmniboxImpl::ConfigureOutgoingConnection( void OmniboxImpl::OnEmbed(mojo::View* root) { if (!aura_init_.get()) { - aura_init_.reset(new AuraInit(app_impl_->shell())); + aura_init_.reset(new AuraInit(root, app_impl_->shell())); edit_ = new views::Textfield; edit_->set_controller(this); } |