diff options
author | ben <ben@chromium.org> | 2015-05-08 11:57:07 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-08 18:58:12 +0000 |
commit | 67837e39863ff7d690585e94f1bb1a6f95bcec23 (patch) | |
tree | 6be6dd7fecfa3db87460b65f840398cc7aca0071 /mandoline | |
parent | d71d576eb65579d20355b817d28502372b4a2331 (diff) | |
download | chromium_src-67837e39863ff7d690585e94f1bb1a6f95bcec23.zip chromium_src-67837e39863ff7d690585e94f1bb1a6f95bcec23.tar.gz chromium_src-67837e39863ff7d690585e94f1bb1a6f95bcec23.tar.bz2 |
Add a simple browser UI (with url bar)
R=sky@chromium.org
BUG=
Review URL: https://codereview.chromium.org/1136593004
Cr-Commit-Position: refs/heads/master@{#329000}
Diffstat (limited to 'mandoline')
-rw-r--r-- | mandoline/ui/BUILD.gn | 9 | ||||
-rw-r--r-- | mandoline/ui/aura/BUILD.gn | 15 | ||||
-rw-r--r-- | mandoline/ui/aura/input_method_mandoline.cc | 77 | ||||
-rw-r--r-- | mandoline/ui/aura/input_method_mandoline.h | 34 | ||||
-rw-r--r-- | mandoline/ui/aura/input_method_mojo_linux.cc | 43 | ||||
-rw-r--r-- | mandoline/ui/aura/input_method_mojo_linux.h | 38 | ||||
-rw-r--r-- | mandoline/ui/aura/native_widget_view_manager.cc | 17 | ||||
-rw-r--r-- | mandoline/ui/aura/surface_context_factory.cc | 7 | ||||
-rw-r--r-- | mandoline/ui/aura/surface_context_factory.h | 1 | ||||
-rw-r--r-- | mandoline/ui/browser/BUILD.gn | 20 | ||||
-rw-r--r-- | mandoline/ui/browser/DEPS | 1 | ||||
-rw-r--r-- | mandoline/ui/browser/android/android_ui.cc | 35 | ||||
-rw-r--r-- | mandoline/ui/browser/android/android_ui.h | 36 | ||||
-rw-r--r-- | mandoline/ui/browser/browser.cc | 23 | ||||
-rw-r--r-- | mandoline/ui/browser/browser.h | 13 | ||||
-rw-r--r-- | mandoline/ui/browser/browser_ui.h | 29 | ||||
-rw-r--r-- | mandoline/ui/browser/desktop/desktop_ui.cc | 99 | ||||
-rw-r--r-- | mandoline/ui/browser/desktop/desktop_ui.h | 53 |
18 files changed, 410 insertions, 140 deletions
diff --git a/mandoline/ui/BUILD.gn b/mandoline/ui/BUILD.gn index d380df3..070e2f4 100644 --- a/mandoline/ui/BUILD.gn +++ b/mandoline/ui/BUILD.gn @@ -5,10 +5,7 @@ import("//third_party/mojo/src/mojo/public/mojo.gni") group("ui") { - if (!is_android) { - deps = [ - "//mandoline/ui/aura", - "//mandoline/ui/browser", - ] - } + deps = [ + "//mandoline/ui/browser", + ] } diff --git a/mandoline/ui/aura/BUILD.gn b/mandoline/ui/aura/BUILD.gn index df7a0ad..25b6195 100644 --- a/mandoline/ui/aura/BUILD.gn +++ b/mandoline/ui/aura/BUILD.gn @@ -7,6 +7,8 @@ source_set("aura") { sources = [ "aura_init.cc", "aura_init.h", + "input_method_mandoline.cc", + "input_method_mandoline.h", "native_widget_view_manager.cc", "native_widget_view_manager.h", "screen_mojo.cc", @@ -19,13 +21,6 @@ source_set("aura") { "window_tree_host_mojo.h", ] - if (is_linux) { - sources += [ - "input_method_mojo_linux.cc", - "input_method_mojo_linux.h", - ] - } - public_deps = [ "//components/view_manager/public/cpp", ] @@ -42,6 +37,7 @@ source_set("aura") { "//skia", "//mojo/cc", "//mojo/converters/geometry", + "//mojo/converters/input_events", "//mojo/converters/surfaces", "//third_party/mojo/src/mojo/public/c/gles2", "//third_party/mojo/src/mojo/public/cpp/application", @@ -54,9 +50,4 @@ source_set("aura") { "//ui/gl", "//ui/views", ] - - data_deps = [ - "//components/native_viewport", - "//components/surfaces", - ] } diff --git a/mandoline/ui/aura/input_method_mandoline.cc b/mandoline/ui/aura/input_method_mandoline.cc new file mode 100644 index 0000000..ac3acb8 --- /dev/null +++ b/mandoline/ui/aura/input_method_mandoline.cc @@ -0,0 +1,77 @@ +// Copyright (c) 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/input_method_mandoline.h" + +#include "ui/base/ime/text_input_client.h" +#include "ui/events/event.h" + +namespace mandoline { + +//////////////////////////////////////////////////////////////////////////////// +// InputMethodMandoline, public: + +InputMethodMandoline::InputMethodMandoline( + ui::internal::InputMethodDelegate* delegate) { + SetDelegate(delegate); +} + +InputMethodMandoline::~InputMethodMandoline() {} + +//////////////////////////////////////////////////////////////////////////////// +// InputMethodMandoline, ui::InputMethod implementation: + +bool InputMethodMandoline::OnUntranslatedIMEMessage( + const base::NativeEvent& event, + NativeEventResult* result) { + return false; +} + +bool InputMethodMandoline::DispatchKeyEvent(const ui::KeyEvent& event) { + DCHECK(event.type() == ui::ET_KEY_PRESSED || + event.type() == ui::ET_KEY_RELEASED); + + // If no text input client, do nothing. + if (!GetTextInputClient()) + return DispatchKeyEventPostIME(event); + + // Here is where we change the differ from our base class's logic. Instead of + // always dispatching a key down event, and then sending a synthesized + // character event, we instead check to see if this is a character event and + // send out the key if it is. (We fallback to normal dispatch if it isn't.) + if (event.is_char()) { + const uint16 ch = event.GetCharacter(); + if (GetTextInputClient()) + GetTextInputClient()->InsertChar(ch, event.flags()); + + return false; + } + + return DispatchKeyEventPostIME(event); +} + +void InputMethodMandoline::OnCaretBoundsChanged( + const ui::TextInputClient* client) { +} + +void InputMethodMandoline::CancelComposition( + const ui::TextInputClient* client) { +} + +void InputMethodMandoline::OnInputLocaleChanged() { +} + +std::string InputMethodMandoline::GetInputLocale() { + return ""; +} + +bool InputMethodMandoline::IsActive() { + return true; +} + +bool InputMethodMandoline::IsCandidatePopupOpen() const { + return false; +} + +} // namespace mandoline diff --git a/mandoline/ui/aura/input_method_mandoline.h b/mandoline/ui/aura/input_method_mandoline.h new file mode 100644 index 0000000..004bfb5 --- /dev/null +++ b/mandoline/ui/aura/input_method_mandoline.h @@ -0,0 +1,34 @@ +// Copyright (c) 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/base/ime/input_method_base.h" + +#ifndef MANDOLINE_UI_AURA_INPUT_METHOD_MANDOLINE_H_ +#define MANDOLINE_UI_AURA_INPUT_METHOD_MANDOLINE_H_ + +namespace mandoline { + +class InputMethodMandoline : public ui::InputMethodBase { + public: + explicit InputMethodMandoline(ui::internal::InputMethodDelegate* delegate); + ~InputMethodMandoline() override; + + private: + // Overridden from ui::InputMethod: + bool OnUntranslatedIMEMessage(const base::NativeEvent& event, + NativeEventResult* result) override; + bool DispatchKeyEvent(const ui::KeyEvent& event) override; + void OnCaretBoundsChanged(const ui::TextInputClient* client) override; + void CancelComposition(const ui::TextInputClient* client) override; + void OnInputLocaleChanged() override; + std::string GetInputLocale() override; + bool IsActive() override; + bool IsCandidatePopupOpen() const override; + + DISALLOW_COPY_AND_ASSIGN(InputMethodMandoline); +}; + +} // namespace mandoline + +#endif // MANDOLINE_UI_AURA_INPUT_METHOD_MANDOLINE_H_ diff --git a/mandoline/ui/aura/input_method_mojo_linux.cc b/mandoline/ui/aura/input_method_mojo_linux.cc deleted file mode 100644 index ea4933f..0000000 --- a/mandoline/ui/aura/input_method_mojo_linux.cc +++ /dev/null @@ -1,43 +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/input_method_mojo_linux.h" - -#include "ui/base/ime/text_input_client.h" -#include "ui/events/event.h" - -namespace mandoline { - -InputMethodMojoLinux::InputMethodMojoLinux( - ui::internal::InputMethodDelegate* delegate) - : ui::InputMethodAuraLinux(delegate) { -} - -InputMethodMojoLinux::~InputMethodMojoLinux() {} - -bool InputMethodMojoLinux::DispatchKeyEvent(const ui::KeyEvent& event) { - DCHECK(event.type() == ui::ET_KEY_PRESSED || - event.type() == ui::ET_KEY_RELEASED); - DCHECK(system_toplevel_window_focused()); - - // If no text input client, do nothing. - if (!GetTextInputClient()) - return DispatchKeyEventPostIME(event); - - // Here is where we change the differ from our base class's logic. Instead of - // always dispatching a key down event, and then sending a synthesized - // character event, we instead check to see if this is a character event and - // send out the key if it is. (We fallback to normal dispatch if it isn't.) - if (event.is_char()) { - const uint16 ch = event.GetCharacter(); - if (GetTextInputClient()) - GetTextInputClient()->InsertChar(ch, event.flags()); - - return false; - } - - return DispatchKeyEventPostIME(event); -} - -} // namespace mandoline diff --git a/mandoline/ui/aura/input_method_mojo_linux.h b/mandoline/ui/aura/input_method_mojo_linux.h deleted file mode 100644 index f5e7fb1..0000000 --- a/mandoline/ui/aura/input_method_mojo_linux.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 MANDOLINE_UI_AURA_INPUT_METHOD_MOJO_LINUX_H_ -#define MANDOLINE_UI_AURA_INPUT_METHOD_MOJO_LINUX_H_ - -#include "ui/base/ime/input_method_auralinux.h" -#include "ui/base/ime/input_method_delegate.h" - -namespace mandoline { - -// An input method for linux that does absolutely no translation. -// -// The current InputMethodMinimal makes assumptions that a system will only -// input/output keydown/keyup events; it assumes that things don't work like -// Windows does. When it gets a keydown event, it then tries to insert a -// character at the same time. -// -// However, we're standardizing on Windows' WM_CHAR style events. This tries to -// follow InputMethodWin::DispatchKeyEvent() instead, because PlatformViewX11 -// now synthesizes a character events so that we have one behaviour across our -// platforms. -class InputMethodMojoLinux : public ui::InputMethodAuraLinux { - public: - explicit InputMethodMojoLinux(ui::internal::InputMethodDelegate* delegate); - ~InputMethodMojoLinux() override; - - // Overriden from ui::InputMethodAuraLinux: - bool DispatchKeyEvent(const ui::KeyEvent& event) override; - - private: - DISALLOW_COPY_AND_ASSIGN(InputMethodMojoLinux); -}; - -} // namespace mandoline - -#endif // MANDOLINE_UI_AURA_INPUT_METHOD_MOJO_LINUX_H_ diff --git a/mandoline/ui/aura/native_widget_view_manager.cc b/mandoline/ui/aura/native_widget_view_manager.cc index d27b600..da6f031 100644 --- a/mandoline/ui/aura/native_widget_view_manager.cc +++ b/mandoline/ui/aura/native_widget_view_manager.cc @@ -4,6 +4,7 @@ #include "mandoline/ui/aura/native_widget_view_manager.h" +#include "mandoline/ui/aura/input_method_mandoline.h" #include "mandoline/ui/aura/window_tree_host_mojo.h" #include "mojo/converters/geometry/geometry_type_converters.h" #include "mojo/converters/input_events/input_events_type_converters.h" @@ -11,19 +12,11 @@ #include "ui/aura/client/default_capture_client.h" #include "ui/aura/window.h" #include "ui/aura/window_event_dispatcher.h" -#include "ui/base/ime/input_method.h" -#include "ui/base/ime/input_method_base.h" #include "ui/base/ime/input_method_delegate.h" -#include "ui/base/ime/input_method_factory.h" -#include "ui/base/ime/text_input_client.h" #include "ui/wm/core/base_focus_rules.h" #include "ui/wm/core/capture_controller.h" #include "ui/wm/core/focus_controller.h" -#if defined(OS_LINUX) -#include "mandoline/ui/aura/input_method_mojo_linux.h" -#endif - namespace mandoline { namespace { @@ -46,12 +39,8 @@ class MinimalInputEventFilter : public ui::internal::InputMethodDelegate, public: explicit MinimalInputEventFilter(aura::Window* root) : root_(root) { - ui::InitializeInputMethodForTesting(); -#if defined(OS_LINUX) - input_method_.reset(new InputMethodMojoLinux(this)); -#else - input_method_ = ui::CreateInputMethod(this, gfx::kNullAcceleratedWidget); -#endif + input_method_.reset(new InputMethodMandoline(this)); + input_method_->OnFocus(); root_->AddPreTargetHandler(this); root_->SetProperty(aura::client::kRootWindowInputMethodKey, input_method_.get()); diff --git a/mandoline/ui/aura/surface_context_factory.cc b/mandoline/ui/aura/surface_context_factory.cc index 0c5af87..1253675 100644 --- a/mandoline/ui/aura/surface_context_factory.cc +++ b/mandoline/ui/aura/surface_context_factory.cc @@ -28,7 +28,8 @@ class FakeReflector : public ui::Reflector { SurfaceContextFactory::SurfaceContextFactory(mojo::Shell* shell, mojo::View* view) - : surface_binding_(shell, view) { + : surface_binding_(shell, view), + next_surface_id_namespace_(1u) { } SurfaceContextFactory::~SurfaceContextFactory() { @@ -88,8 +89,8 @@ cc::TaskGraphRunner* SurfaceContextFactory::GetTaskGraphRunner() { scoped_ptr<cc::SurfaceIdAllocator> SurfaceContextFactory::CreateSurfaceIdAllocator() { - NOTIMPLEMENTED(); - return nullptr; + return make_scoped_ptr( + new cc::SurfaceIdAllocator(next_surface_id_namespace_++)); } void SurfaceContextFactory::ResizeDisplay(ui::Compositor* compositor, diff --git a/mandoline/ui/aura/surface_context_factory.h b/mandoline/ui/aura/surface_context_factory.h index 9eb3a20..1a76e29 100644 --- a/mandoline/ui/aura/surface_context_factory.h +++ b/mandoline/ui/aura/surface_context_factory.h @@ -39,6 +39,7 @@ class SurfaceContextFactory : public ui::ContextFactory { const gfx::Size& size) override; SurfaceBinding surface_binding_; + uint32_t next_surface_id_namespace_; DISALLOW_COPY_AND_ASSIGN(SurfaceContextFactory); }; diff --git a/mandoline/ui/browser/BUILD.gn b/mandoline/ui/browser/BUILD.gn index 3a21071..ff404f9 100644 --- a/mandoline/ui/browser/BUILD.gn +++ b/mandoline/ui/browser/BUILD.gn @@ -21,12 +21,9 @@ mojo_native_application("window_manager") { "//mandoline/services/navigation/public/interfaces", "//mojo/application", "//mojo/common:common", - "//mojo/converters/geometry", "//third_party/mojo/src/mojo/public/cpp/bindings", "//third_party/mojo/src/mojo/public/cpp/utility", "//third_party/mojo/src/mojo/public/interfaces/application", - "//ui/gfx/geometry", - "//ui/mojo/events:interfaces", ] } @@ -40,16 +37,33 @@ source_set("kiosk_wm_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 = [ "//base", "//components/view_manager/public/cpp", "//components/window_manager:lib", "//mandoline/services/navigation/public/interfaces", "//mojo/converters/geometry", + "//skia", "//third_party/mojo/src/mojo/public/cpp/bindings", "//third_party/mojo/src/mojo/public/cpp/utility", "//third_party/mojo/src/mojo/public/interfaces/application", "//ui/gfx/geometry", "//ui/mojo/events:interfaces", ] + + if (!is_android) { + deps += [ "//mandoline/ui/aura" ] + } } diff --git a/mandoline/ui/browser/DEPS b/mandoline/ui/browser/DEPS index 8606349..d9b36c3 100644 --- a/mandoline/ui/browser/DEPS +++ b/mandoline/ui/browser/DEPS @@ -4,6 +4,7 @@ include_rules = [ "+mandoline/services", "+mojo/application", "+mojo/common", + "+mojo/converters", "+third_party/mojo/src/mojo/public", "+third_party/mojo_services", "+ui", diff --git a/mandoline/ui/browser/android/android_ui.cc b/mandoline/ui/browser/android/android_ui.cc new file mode 100644 index 0000000..3a414c6 --- /dev/null +++ b/mandoline/ui/browser/android/android_ui.cc @@ -0,0 +1,35 @@ +// 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/browser/android/android_ui.h" + +namespace mojo { +class Shell; +class View; +} + +namespace mandoline { + +class Browser; + +AndroidUI::AndroidUI(Browser* browser, mojo::Shell* shell) + : browser_(browser), + shell_(shell), + root_(nullptr), + content_(nullptr) {} +AndroidUI::~AndroidUI() {} + +void AndroidUI::Init(mojo::View* root, mojo::View* content_) { + root_ = root; + content_ = content; + + content_->SetBounds(root_->bounds()); +} + +// static +BrowserUI* BrowserUI::Create(Browser* browser, mojo::Shell* shell) { + return new AndroidUI(browser, shell); +} + +} // namespace mandoline diff --git a/mandoline/ui/browser/android/android_ui.h b/mandoline/ui/browser/android/android_ui.h new file mode 100644 index 0000000..1f90df0 --- /dev/null +++ b/mandoline/ui/browser/android/android_ui.h @@ -0,0 +1,36 @@ +// 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_BROWSER_ANDROID_ANDROID_UI_H_ +#define MANDOLINE_UI_BROWSER_ANDROID_ANDROID_UI_H_ + +namespace mojo { +class Shell; +class View; +} + +namespace mandoline { + +class Browser; + +class AndroidUI : public BrowserUI { + public: + AndroidUI(Browser* browser, mojo::Shell* shell); + ~AndroidUI() override; + + private: + // Overridden from BrowserUI: + void Init(mojo::View* root, mojo::View* content) override; + + Browser* browser_; + mojo::Shell* shell_; + mojo::View* root_; + mojo::View* content_; + + DISALLOW_COPY_AND_ASSIGN(AndroidUI); +}; + +} // namespace mandoline + +#endif // MANDOLINE_UI_BROWSER_ANDROID_ANDROID_UI_H_ diff --git a/mandoline/ui/browser/browser.cc b/mandoline/ui/browser/browser.cc index d6abe10..d62d127 100644 --- a/mandoline/ui/browser/browser.cc +++ b/mandoline/ui/browser/browser.cc @@ -6,7 +6,10 @@ #include "base/command_line.h" #include "base/strings/utf_string_conversions.h" +#include "mandoline/ui/browser/browser_ui.h" #include "mandoline/ui/browser/merged_service_provider.h" +#include "mojo/application/application_runner_chromium.h" +#include "third_party/mojo/src/mojo/public/c/system/main.h" #include "ui/gfx/geometry/size.h" namespace mandoline { @@ -16,6 +19,7 @@ Browser::Browser() root_(nullptr), content_(nullptr), navigator_host_(this), + ui_(nullptr), weak_factory_(this) { exposed_services_impl_.AddService(this); } @@ -29,6 +33,7 @@ base::WeakPtr<Browser> Browser::GetWeakPtr() { void Browser::Initialize(mojo::ApplicationImpl* app) { window_manager_app_->Initialize(app); + ui_.reset(BrowserUI::Create(this, app->shell())); base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); base::CommandLine::StringVector args = command_line->GetArgs(); @@ -62,8 +67,12 @@ void Browser::OnEmbed( // Browser does not support being embedded more than once. CHECK(!root_); + // 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; - root_->AddObserver(this); + content_ = root->view_manager()->CreateView(); + ui_->Init(root_, content_); #if defined(OS_ANDROID) // Resize to match the Nexus 5 aspect ratio: @@ -72,8 +81,6 @@ void Browser::OnEmbed( window_manager_app_->SetViewportSize(gfx::Size(1280, 800)); #endif - content_ = root->view_manager()->CreateView(); - content_->SetBounds(root_->bounds()); root_->AddChild(content_); content_->SetVisible(true); @@ -123,16 +130,6 @@ void Browser::OnViewManagerDisconnected( root_ = nullptr; } -void Browser::OnViewDestroyed(mojo::View* view) { - view->RemoveObserver(this); -} - -void Browser::OnViewBoundsChanged(mojo::View* view, - const mojo::Rect& old_bounds, - const mojo::Rect& new_bounds) { - content_->SetBounds(new_bounds); -} - // Convenience method: void Browser::ReplaceContentWithURL(const mojo::String& url) { Embed(url, nullptr, nullptr); diff --git a/mandoline/ui/browser/browser.h b/mandoline/ui/browser/browser.h index e8d737a..3347084 100644 --- a/mandoline/ui/browser/browser.h +++ b/mandoline/ui/browser/browser.h @@ -8,7 +8,6 @@ #include "base/memory/weak_ptr.h" #include "components/view_manager/public/cpp/view_manager.h" #include "components/view_manager/public/cpp/view_manager_delegate.h" -#include "components/view_manager/public/cpp/view_observer.h" #include "components/window_manager/window_manager_app.h" #include "components/window_manager/window_manager_delegate.h" #include "mandoline/services/navigation/public/interfaces/navigation.mojom.h" @@ -21,11 +20,11 @@ namespace mandoline { +class BrowserUI; class MergedServiceProvider; class Browser : public mojo::ApplicationDelegate, public mojo::ViewManagerDelegate, - public mojo::ViewObserver, public window_manager::WindowManagerDelegate, public mojo::InterfaceFactory<mojo::NavigatorHost> { public: @@ -50,12 +49,6 @@ class Browser : public mojo::ApplicationDelegate, mojo::ServiceProviderPtr exposed_services) override; void OnViewManagerDisconnected(mojo::ViewManager* view_manager) override; - // Overriden from mojo::ViewObserver: - void OnViewDestroyed(mojo::View* view) override; - void OnViewBoundsChanged(mojo::View* view, - const mojo::Rect& old_bounds, - const mojo::Rect& new_bounds) override; - // Overridden from WindowManagerDelegate: void Embed(const mojo::String& url, mojo::InterfaceRequest<mojo::ServiceProvider> services, @@ -68,6 +61,8 @@ class Browser : public mojo::ApplicationDelegate, void Create(mojo::ApplicationConnection* connection, mojo::InterfaceRequest<mojo::NavigatorHost> request) override; + void LayoutContent(); + scoped_ptr<window_manager::WindowManagerApp> window_manager_app_; // Only support being embedded once, so both application-level @@ -82,6 +77,8 @@ class Browser : public mojo::ApplicationDelegate, NavigatorHostImpl navigator_host_; + scoped_ptr<BrowserUI> ui_; + base::WeakPtrFactory<Browser> weak_factory_; DISALLOW_COPY_AND_ASSIGN(Browser); diff --git a/mandoline/ui/browser/browser_ui.h b/mandoline/ui/browser/browser_ui.h new file mode 100644 index 0000000..f924de7 --- /dev/null +++ b/mandoline/ui/browser/browser_ui.h @@ -0,0 +1,29 @@ +// 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_BROWSER_BROWSER_UI_H_ +#define MANDOLINE_UI_BROWSER_BROWSER_UI_H_ + +namespace mojo { +class Shell; +class View; +} + +namespace mandoline { + +class Browser; + +class BrowserUI { + public: + virtual ~BrowserUI() {} + static BrowserUI* Create(Browser* browser, mojo::Shell* shell); + + // Called when the Browser UI is embedded within the specified view. + virtual void Init(mojo::View* root, mojo::View* content) = 0; + +}; + +} // namespace mandoline + +#endif // MANDOLINE_UI_BROWSER_BROWSER_UI_H_ diff --git a/mandoline/ui/browser/desktop/desktop_ui.cc b/mandoline/ui/browser/desktop/desktop_ui.cc new file mode 100644 index 0000000..d2fc927 --- /dev/null +++ b/mandoline/ui/browser/desktop/desktop_ui.cc @@ -0,0 +1,99 @@ +// 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/browser/desktop/desktop_ui.h" + +#include "base/strings/string16.h" +#include "mandoline/ui/aura/native_widget_view_manager.h" +#include "mandoline/ui/browser/browser.h" +#include "mojo/common/common_type_converters.h" +#include "mojo/converters/geometry/geometry_type_converters.h" +#include "ui/views/background.h" +#include "ui/views/controls/textfield/textfield.h" +#include "ui/views/widget/widget_delegate.h" + +namespace mandoline { + +//////////////////////////////////////////////////////////////////////////////// +// DesktopUI, public: + +DesktopUI::DesktopUI(Browser* browser, mojo::Shell* shell) + : browser_(browser), + shell_(shell), + omnibox_(new views::Textfield), + root_(nullptr), + content_(nullptr) { + omnibox_->set_controller(this); +} + +DesktopUI::~DesktopUI() {} + +//////////////////////////////////////////////////////////////////////////////// +// DesktopUI, BrowserUI implementation: + +void DesktopUI::Init(mojo::View* root, mojo::View* content) { + root_ = root; + content_ = content; + + views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; + widget_delegate->GetContentsView()->set_background( + views::Background::CreateSolidBackground(0xFFDDDDDD)); + widget_delegate->GetContentsView()->AddChildView(omnibox_); + widget_delegate->GetContentsView()->SetLayoutManager(this); + + views::Widget* widget = new views::Widget; + views::Widget::InitParams params( + views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); + params.native_widget = new NativeWidgetViewManager(widget, shell_, root_); + params.delegate = widget_delegate; + params.bounds = root_->bounds().To<gfx::Rect>(); + widget->Init(params); + widget->Show(); + root_->SetFocus(); + omnibox_->RequestFocus(); +} + +//////////////////////////////////////////////////////////////////////////////// +// DesktopUI, views::LayoutManager implementation: + +gfx::Size DesktopUI::GetPreferredSize(const views::View* view) const { + return gfx::Size(); +} + +void DesktopUI::Layout(views::View* host) { + gfx::Rect omnibox_bounds = host->bounds(); + omnibox_bounds.Inset(10, 10, 10, host->bounds().height() - 40); + omnibox_->SetBoundsRect(omnibox_bounds); + + mojo::Rect content_bounds_mojo; + content_bounds_mojo.x = omnibox_bounds.x(); + content_bounds_mojo.y = omnibox_bounds.bottom() + 10; + content_bounds_mojo.width = omnibox_bounds.width(); + content_bounds_mojo.height = + host->bounds().height() - content_bounds_mojo.y - 10; + content_->SetBounds(content_bounds_mojo); +} + +//////////////////////////////////////////////////////////////////////////////// +// DesktopUI, views::TextfieldController implementation: + +bool DesktopUI::HandleKeyEvent(views::Textfield* sender, + const ui::KeyEvent& key_event) { + if (key_event.key_code() == ui::VKEY_RETURN) { + browser_->ReplaceContentWithURL( + mojo::String::From<base::string16>(sender->text())); + return true; + } + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +// BrowserUI, public: + +// static +BrowserUI* BrowserUI::Create(Browser* browser, mojo::Shell* shell) { + return new DesktopUI(browser, shell); +} + +} // namespace mandoline diff --git a/mandoline/ui/browser/desktop/desktop_ui.h b/mandoline/ui/browser/desktop/desktop_ui.h new file mode 100644 index 0000000..c3167b0d --- /dev/null +++ b/mandoline/ui/browser/desktop/desktop_ui.h @@ -0,0 +1,53 @@ +// 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_BROWSER_DESKTOP_DESKTOP_UI_H_ +#define MANDOLINE_UI_BROWSER_DESKTOP_DESKTOP_UI_H_ + +#include "mandoline/ui/aura/aura_init.h" +#include "mandoline/ui/browser/browser_ui.h" +#include "ui/views/controls/textfield/textfield_controller.h" +#include "ui/views/layout/layout_manager.h" + +namespace mojo { +class Shell; +class View; +} + +namespace mandoline { + +class Browser; + +class DesktopUI : public BrowserUI, + public views::LayoutManager, + public views::TextfieldController { + public: + DesktopUI(Browser* browser, mojo::Shell* shell); + ~DesktopUI() override; + + private: + // Overridden from BrowserUI + void Init(mojo::View* root, mojo::View* content) override; + + // Overridden from views::LayoutManager: + gfx::Size GetPreferredSize(const views::View* view) const override; + void Layout(views::View* host) override; + + // Overridden from views::TextfieldController: + bool HandleKeyEvent(views::Textfield* sender, + const ui::KeyEvent& key_event) override; + + AuraInit aura_init_; + Browser* browser_; + mojo::Shell* shell_; + views::Textfield* omnibox_; + mojo::View* root_; + mojo::View* content_; + + DISALLOW_COPY_AND_ASSIGN(DesktopUI); +}; + +} // namespace mandoline + +#endif // MANDOLINE_UI_BROWSER_DESKTOP_DESKTOP_UI_H_ |