summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky <sky@chromium.org>2015-06-18 17:55:20 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-19 00:56:49 +0000
commitf760367972c3f3fb5143e7cea5bd6fc29ec3a0a9 (patch)
tree27193718b69445158806ae2bc3086cec8f2e3c76
parent0e90449a7c9bd8f051fce4988a8cccd6c1c64661 (diff)
downloadchromium_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}
-rw-r--r--components/html_viewer/BUILD.gn4
-rw-r--r--components/html_viewer/DEPS1
-rw-r--r--components/html_viewer/setup.cc10
-rw-r--r--components/html_viewer/setup.h9
-rw-r--r--components/html_viewer/ui_setup.h28
-rw-r--r--components/html_viewer/ui_setup_android.cc115
-rw-r--r--components/html_viewer/ui_setup_android.h38
-rw-r--r--mandoline/ui/aura/BUILD.gn3
-rw-r--r--mandoline/ui/aura/DEPS1
-rw-r--r--mandoline/ui/aura/aura_init.cc11
-rw-r--r--mandoline/ui/aura/aura_init.h9
-rw-r--r--mandoline/ui/browser/browser.cc33
-rw-r--r--mandoline/ui/browser/browser.h6
-rw-r--r--mandoline/ui/browser/browser_manager.cc69
-rw-r--r--mandoline/ui/browser/browser_manager.h13
-rw-r--r--mandoline/ui/omnibox/omnibox_impl.cc2
-rw-r--r--ui/mojo/init/BUILD.gn24
-rw-r--r--ui/mojo/init/DEPS4
-rw-r--r--ui/mojo/init/screen_mojo.cc (renamed from mandoline/ui/aura/screen_mojo.cc)66
-rw-r--r--ui/mojo/init/screen_mojo.h (renamed from mandoline/ui/aura/screen_mojo.h)35
-rw-r--r--ui/mojo/init/ui_init.cc59
-rw-r--r--ui/mojo/init/ui_init.h43
22 files changed, 306 insertions, 277 deletions
diff --git a/components/html_viewer/BUILD.gn b/components/html_viewer/BUILD.gn
index 1ff16e64..0fce7c5 100644
--- a/components/html_viewer/BUILD.gn
+++ b/components/html_viewer/BUILD.gn
@@ -143,6 +143,7 @@ source_set("lib") {
"//ui/events/gestures/blink",
"//ui/gfx",
"//ui/gfx/geometry",
+ "//ui/mojo/init",
"//ui/native_theme",
# TODO(sky): we shouldn't be using ui_test_pak.
@@ -170,9 +171,6 @@ source_set("lib") {
mojo_native_application("html_viewer") {
sources = [
"html_viewer.cc",
- "ui_setup.h",
- "ui_setup_android.cc",
- "ui_setup_android.h",
]
deps = [
":html_viewer_resources_grit",
diff --git a/components/html_viewer/DEPS b/components/html_viewer/DEPS
index 0a5b15a..6a70ad0 100644
--- a/components/html_viewer/DEPS
+++ b/components/html_viewer/DEPS
@@ -36,6 +36,7 @@ include_rules = [
"+ui/gfx",
"+ui/mojo/events",
"+ui/mojo/geometry",
+ "+ui/mojo/init",
"+ui/native_theme",
"+v8/include",
]
diff --git a/components/html_viewer/setup.cc b/components/html_viewer/setup.cc
index 928f617..6a8562b 100644
--- a/components/html_viewer/setup.cc
+++ b/components/html_viewer/setup.cc
@@ -19,14 +19,9 @@
#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
+#include "ui/mojo/init/ui_init.h"
#include "v8/include/v8.h"
-#if defined(OS_ANDROID)
-#include "components/html_viewer/ui_setup_android.h"
-#else
-#include "components/html_viewer/ui_setup.h"
-#endif
-
namespace html_viewer {
namespace {
@@ -102,7 +97,8 @@ void Setup::InitIfNecessary(const gfx::Size& screen_size_in_pixels,
return;
}
- ui_setup_.reset(new UISetup(screen_size_in_pixels, device_pixel_ratio));
+ ui_init_.reset(
+ new ui::mojo::UIInit(screen_size_in_pixels, device_pixel_ratio));
base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_);
renderer_scheduler_ = scheduler::RendererScheduler::Create();
diff --git a/components/html_viewer/setup.h b/components/html_viewer/setup.h
index 941f3182..83154b5 100644
--- a/components/html_viewer/setup.h
+++ b/components/html_viewer/setup.h
@@ -19,6 +19,12 @@ class ApplicationImpl;
class Shell;
}
+namespace ui {
+namespace mojo {
+class UIInit;
+}
+}
+
namespace scheduler {
class RendererScheduler;
}
@@ -26,7 +32,6 @@ class RendererScheduler;
namespace html_viewer {
class BlinkPlatformImpl;
-class UISetup;
class MediaFactory;
// Setup encapsulates the necessary state needed by HTMLViewer. Some objects
@@ -87,7 +92,7 @@ class Setup {
gfx::Size screen_size_in_pixels_;
- scoped_ptr<UISetup> ui_setup_;
+ scoped_ptr<ui::mojo::UIInit> ui_init_;
// Skia requires that we have one of these. Unlike the one used in chrome,
// this doesn't use purgable shared memory. Instead, it tries to free the
diff --git a/components/html_viewer/ui_setup.h b/components/html_viewer/ui_setup.h
deleted file mode 100644
index 7ab0915..0000000
--- a/components/html_viewer/ui_setup.h
+++ /dev/null
@@ -1,28 +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 COMPONENTS_HTML_VIEWER_UI_SETUP_H_
-#define COMPONENTS_HTML_VIEWER_UI_SETUP_H_
-
-#include "base/basictypes.h"
-
-namespace gfx {
-class Size;
-}
-
-namespace html_viewer {
-
-// UISetup is intended for platform specific UI setup.
-class UISetup {
- public:
- UISetup(const gfx::Size& screen_size_in_pixels, float device_pixel_ratio) {}
- ~UISetup() {}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(UISetup);
-};
-
-} // namespace html_viewer
-
-#endif // COMPONENTS_HTML_VIEWER_UI_SETUP_H_
diff --git a/components/html_viewer/ui_setup_android.cc b/components/html_viewer/ui_setup_android.cc
deleted file mode 100644
index 5fbbc72..0000000
--- a/components/html_viewer/ui_setup_android.cc
+++ /dev/null
@@ -1,115 +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 "components/html_viewer/ui_setup_android.h"
-
-#include "base/memory/singleton.h"
-#include "ui/events/gesture_detection/gesture_configuration.h"
-#include "ui/gfx/geometry/size_conversions.h"
-#include "ui/gfx/screen.h"
-
-namespace html_viewer {
-namespace {
-
-class ScreenMandoline : public gfx::Screen {
- public:
- ScreenMandoline(const gfx::Size& screen_size_in_pixels,
- float device_pixel_ratio)
- : screen_size_in_pixels_(screen_size_in_pixels),
- device_pixel_ratio_(device_pixel_ratio) {}
-
- gfx::Point GetCursorScreenPoint() override { return gfx::Point(); }
-
- gfx::NativeWindow GetWindowUnderCursor() override {
- NOTIMPLEMENTED();
- return NULL;
- }
-
- gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override {
- NOTIMPLEMENTED();
- return NULL;
- }
-
- gfx::Display GetPrimaryDisplay() const override {
- const gfx::Rect bounds_in_pixels(gfx::Point(), screen_size_in_pixels_);
- const gfx::Rect bounds_in_dip(gfx::ToCeiledSize(
- gfx::ScaleSize(bounds_in_pixels.size(), 1.0f / device_pixel_ratio_)));
- gfx::Display display(0, bounds_in_dip);
- display.set_device_scale_factor(device_pixel_ratio_);
- return display;
- }
-
- gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override {
- return GetPrimaryDisplay();
- }
-
- gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override {
- return GetPrimaryDisplay();
- }
-
- int GetNumDisplays() const override { return 1; }
-
- std::vector<gfx::Display> GetAllDisplays() const override {
- return std::vector<gfx::Display>(1, GetPrimaryDisplay());
- }
-
- gfx::Display GetDisplayMatching(const gfx::Rect& match_rect) const override {
- return GetPrimaryDisplay();
- }
-
- void AddObserver(gfx::DisplayObserver* observer) override {
- // no display change on Android.
- }
-
- void RemoveObserver(gfx::DisplayObserver* observer) override {
- // no display change on Android.
- }
-
- private:
- const gfx::Size screen_size_in_pixels_;
- const float device_pixel_ratio_;
-
- DISALLOW_COPY_AND_ASSIGN(ScreenMandoline);
-};
-
-} // namespace
-
-// TODO(sky): this needs to come from system.
-class GestureConfigurationMandoline : public ui::GestureConfiguration {
- public:
- GestureConfigurationMandoline() : GestureConfiguration() {
- set_double_tap_enabled(false);
- set_double_tap_timeout_in_ms(semi_long_press_time_in_ms());
- set_gesture_begin_end_types_enabled(true);
- set_min_gesture_bounds_length(default_radius());
- set_min_pinch_update_span_delta(0);
- set_min_scaling_touch_major(default_radius() * 2);
- set_velocity_tracker_strategy(
- ui::VelocityTracker::Strategy::LSQ2_RESTRICTED);
- set_span_slop(max_touch_move_in_pixels_for_click() * 2);
- set_swipe_enabled(true);
- set_two_finger_tap_enabled(true);
- }
-
- ~GestureConfigurationMandoline() override {}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(GestureConfigurationMandoline);
-};
-
-UISetup::UISetup(const gfx::Size& screen_size_in_pixels,
- float device_pixel_ratio)
- : screen_(new ScreenMandoline(screen_size_in_pixels, device_pixel_ratio)),
- gesture_configuration_(new GestureConfigurationMandoline) {
- gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE,
- screen_.get());
- ui::GestureConfiguration::SetInstance(gesture_configuration_.get());
-}
-
-UISetup::~UISetup() {
- gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, nullptr);
- ui::GestureConfiguration::SetInstance(nullptr);
-}
-
-} // namespace html_viewer
diff --git a/components/html_viewer/ui_setup_android.h b/components/html_viewer/ui_setup_android.h
deleted file mode 100644
index d9638e1..0000000
--- a/components/html_viewer/ui_setup_android.h
+++ /dev/null
@@ -1,38 +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 COMPONENTS_HTML_VIEWER_UI_SETUP_ANDROID_H_
-#define COMPONENTS_HTML_VIEWER_UI_SETUP_ANDROID_H_
-
-#include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
-
-namespace gfx {
-class Screen;
-class Size;
-}
-
-namespace ui {
-class GestureConfiguration;
-}
-
-namespace html_viewer {
-
-class GestureConfigurationMandoline;
-
-class UISetup {
- public:
- UISetup(const gfx::Size& screen_size_in_pixels, float device_pixel_ratio);
- ~UISetup();
-
- private:
- scoped_ptr<gfx::Screen> screen_;
- scoped_ptr<GestureConfigurationMandoline> gesture_configuration_;
-
- DISALLOW_COPY_AND_ASSIGN(UISetup);
-};
-
-} // namespace html_viewer
-
-#endif // COMPONENTS_HTML_VIEWER_UI_SETUP_ANDROID_H_
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/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);
}
diff --git a/ui/mojo/init/BUILD.gn b/ui/mojo/init/BUILD.gn
new file mode 100644
index 0000000..e6745ad
--- /dev/null
+++ b/ui/mojo/init/BUILD.gn
@@ -0,0 +1,24 @@
+# Copyright 2014 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.
+
+source_set("init") {
+ sources = [
+ "screen_mojo.cc",
+ "screen_mojo.h",
+ "ui_init.cc",
+ "ui_init.h",
+ ]
+
+ deps = [
+ "//base",
+ "//ui/gfx/geometry",
+ ]
+
+ if (is_android) {
+ deps += [
+ "//ui/events:gesture_detection",
+ "//ui/gfx",
+ ]
+ }
+}
diff --git a/ui/mojo/init/DEPS b/ui/mojo/init/DEPS
new file mode 100644
index 0000000..e419b31
--- /dev/null
+++ b/ui/mojo/init/DEPS
@@ -0,0 +1,4 @@
+include_rules = [
+ "+ui/events/gesture_detection",
+ "+ui/gfx",
+]
diff --git a/mandoline/ui/aura/screen_mojo.cc b/ui/mojo/init/screen_mojo.cc
index b15a68e..1ed0d41 100644
--- a/mandoline/ui/aura/screen_mojo.cc
+++ b/ui/mojo/init/screen_mojo.cc
@@ -2,72 +2,66 @@
// 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/mojo/init/screen_mojo.h"
-#include "ui/gfx/geometry/rect_conversions.h"
-#include "ui/gfx/native_widget_types.h"
+namespace ui {
+namespace mojo {
-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() {
+ScreenMojo::ScreenMojo(const gfx::Size& screen_size_in_pixels,
+ float device_pixel_ratio)
+ : screen_size_in_pixels_(screen_size_in_pixels),
+ device_pixel_ratio_(device_pixel_ratio) {
+ static int64 synthesized_display_id = 2000;
+ display_.set_id(synthesized_display_id++);
+ display_.SetScaleAndBounds(device_pixel_ratio,
+ gfx::Rect(screen_size_in_pixels));
}
gfx::Point ScreenMojo::GetCursorScreenPoint() {
- NOTIMPLEMENTED();
return gfx::Point();
}
gfx::NativeWindow ScreenMojo::GetWindowUnderCursor() {
- return GetWindowAtScreenPoint(GetCursorScreenPoint());
+ NOTIMPLEMENTED();
+ return nullptr;
}
gfx::NativeWindow ScreenMojo::GetWindowAtScreenPoint(const gfx::Point& point) {
NOTIMPLEMENTED();
- return NULL;
+ return nullptr;
}
-int ScreenMojo::GetNumDisplays() const {
- return 1;
+gfx::Display ScreenMojo::GetPrimaryDisplay() const {
+ return display_;
}
-std::vector<gfx::Display> ScreenMojo::GetAllDisplays() const {
- return std::vector<gfx::Display>(1, display_);
+gfx::Display ScreenMojo::GetDisplayNearestWindow(gfx::NativeView view) const {
+ return GetPrimaryDisplay();
}
-gfx::Display ScreenMojo::GetDisplayNearestWindow(
- gfx::NativeWindow window) const {
- return display_;
+gfx::Display ScreenMojo::GetDisplayNearestPoint(const gfx::Point& point) const {
+ return GetPrimaryDisplay();
}
-gfx::Display ScreenMojo::GetDisplayNearestPoint(const gfx::Point& point) const {
- return display_;
+int ScreenMojo::GetNumDisplays() const {
+ return 1;
}
-gfx::Display ScreenMojo::GetDisplayMatching(const gfx::Rect& match_rect) const {
- return display_;
+std::vector<gfx::Display> ScreenMojo::GetAllDisplays() const {
+ return std::vector<gfx::Display>(1, GetPrimaryDisplay());
}
-gfx::Display ScreenMojo::GetPrimaryDisplay() const {
- return display_;
+gfx::Display ScreenMojo::GetDisplayMatching(const gfx::Rect& match_rect) const {
+ return GetPrimaryDisplay();
}
void ScreenMojo::AddObserver(gfx::DisplayObserver* observer) {
+ // TODO: add support for display changes.
}
void ScreenMojo::RemoveObserver(gfx::DisplayObserver* observer) {
+ // TODO: add support for display changes.
}
-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
+} // namespace mojo
+} // namespace ui
diff --git a/mandoline/ui/aura/screen_mojo.h b/ui/mojo/init/screen_mojo.h
index 964c21a..db7f48f 100644
--- a/mandoline/ui/aura/screen_mojo.h
+++ b/ui/mojo/init/screen_mojo.h
@@ -2,48 +2,43 @@
// 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_
+#ifndef UI_MOJO_INIT_SCREEN_MOJO_H_
+#define UI_MOJO_INIT_SCREEN_MOJO_H_
-#include "base/macros.h"
#include "ui/gfx/display.h"
+#include "ui/gfx/geometry/size.h"
#include "ui/gfx/screen.h"
-namespace gfx {
-class Rect;
-class Transform;
-}
+namespace ui {
+namespace mojo {
-namespace mandoline {
-
-// A minimal implementation of gfx::Screen for mojo.
class ScreenMojo : public gfx::Screen {
public:
- static ScreenMojo* Create();
- ~ScreenMojo() override;
+ ScreenMojo(const gfx::Size& screen_size_in_pixels, float device_pixel_ratio);
- protected:
- // gfx::Screen overrides:
+ // gfx::Screen:
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 GetPrimaryDisplay() const override;
gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override;
gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override;
+ int GetNumDisplays() const override;
+ std::vector<gfx::Display> GetAllDisplays() 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);
+ const gfx::Size screen_size_in_pixels_;
+ const float device_pixel_ratio_;
gfx::Display display_;
DISALLOW_COPY_AND_ASSIGN(ScreenMojo);
};
-} // namespace mandoline
+} // namespace mojo
+} // namespace ui
-#endif // MANDOLINE_UI_AURA_SCREEN_MOJO_H_
+#endif // UI_MOJO_INIT_SCREEN_MOJO_H_
diff --git a/ui/mojo/init/ui_init.cc b/ui/mojo/init/ui_init.cc
new file mode 100644
index 0000000..937112e
--- /dev/null
+++ b/ui/mojo/init/ui_init.cc
@@ -0,0 +1,59 @@
+// 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/mojo/init/ui_init.h"
+
+#include "base/memory/singleton.h"
+#include "ui/mojo/init/screen_mojo.h"
+
+#if defined(OS_ANDROID)
+#include "ui/events/gesture_detection/gesture_configuration.h"
+#endif
+
+namespace ui {
+namespace mojo {
+
+#if defined(OS_ANDROID)
+// TODO(sky): this needs to come from system.
+class GestureConfigurationMojo : public ui::GestureConfiguration {
+ public:
+ GestureConfigurationMojo() : GestureConfiguration() {
+ set_double_tap_enabled(false);
+ set_double_tap_timeout_in_ms(semi_long_press_time_in_ms());
+ set_gesture_begin_end_types_enabled(true);
+ set_min_gesture_bounds_length(default_radius());
+ set_min_pinch_update_span_delta(0);
+ set_min_scaling_touch_major(default_radius() * 2);
+ set_velocity_tracker_strategy(
+ ui::VelocityTracker::Strategy::LSQ2_RESTRICTED);
+ set_span_slop(max_touch_move_in_pixels_for_click() * 2);
+ set_swipe_enabled(true);
+ set_two_finger_tap_enabled(true);
+ }
+
+ ~GestureConfigurationMojo() override {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(GestureConfigurationMojo);
+};
+#endif
+
+UIInit::UIInit(const gfx::Size& screen_size_in_pixels, float device_pixel_ratio)
+ : screen_(new ScreenMojo(screen_size_in_pixels, device_pixel_ratio)) {
+ gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
+#if defined(OS_ANDROID)
+ gesture_configuration_.reset(new GestureConfigurationMojo);
+ ui::GestureConfiguration::SetInstance(gesture_configuration_.get());
+#endif
+}
+
+UIInit::~UIInit() {
+ gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, nullptr);
+#if defined(OS_ANDROID)
+ ui::GestureConfiguration::SetInstance(nullptr);
+#endif
+}
+
+} // namespace mojo
+} // namespace ui
diff --git a/ui/mojo/init/ui_init.h b/ui/mojo/init/ui_init.h
new file mode 100644
index 0000000..eeaebc6
--- /dev/null
+++ b/ui/mojo/init/ui_init.h
@@ -0,0 +1,43 @@
+// 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 UI_MOJO_INIT_UI_INIT_H_
+#define UI_MOJO_INIT_UI_INIT_H_
+
+#include "base/basictypes.h"
+#include "base/callback_forward.h"
+#include "base/memory/scoped_ptr.h"
+
+namespace gfx {
+class Screen;
+class Size;
+}
+
+namespace ui {
+class GestureConfiguration;
+
+namespace mojo {
+
+class GestureConfigurationMojo;
+
+// UIInit configures any state needed by apps that make use of ui classes (not
+// including aura).
+class UIInit {
+ public:
+ UIInit(const gfx::Size& screen_size_in_pixels, float device_pixel_ratio);
+ ~UIInit();
+
+ private:
+ scoped_ptr<gfx::Screen> screen_;
+#if defined(OS_ANDROID)
+ scoped_ptr<GestureConfigurationMojo> gesture_configuration_;
+#endif
+
+ DISALLOW_COPY_AND_ASSIGN(UIInit);
+};
+
+} // namespace mojo
+} // namespace ui
+
+#endif // UI_MOJO_INIT_UI_INIT_H_