Commit 67837e39 authored by ben's avatar ben Committed by Commit bot

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}
parent d71d576e
......@@ -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",
]
}
......@@ -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",
]
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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_mojo_linux.h"
#include "mandoline/ui/aura/input_method_mandoline.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) {
////////////////////////////////////////////////////////////////////////////////
// InputMethodMandoline, public:
InputMethodMandoline::InputMethodMandoline(
ui::internal::InputMethodDelegate* delegate) {
SetDelegate(delegate);
}
InputMethodMojoLinux::~InputMethodMojoLinux() {}
InputMethodMandoline::~InputMethodMandoline() {}
////////////////////////////////////////////////////////////////////////////////
// InputMethodMandoline, ui::InputMethod implementation:
bool InputMethodMandoline::OnUntranslatedIMEMessage(
const base::NativeEvent& event,
NativeEventResult* result) {
return false;
}
bool InputMethodMojoLinux::DispatchKeyEvent(const ui::KeyEvent& event) {
bool InputMethodMandoline::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())
......@@ -40,4 +51,27 @@ bool InputMethodMojoLinux::DispatchKeyEvent(const ui::KeyEvent& event) {
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
// 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_
// 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_
......@@ -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());
......
......@@ -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,
......
......@@ -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);
};
......
......@@ -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" ]
}
}
......@@ -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",
......
// 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
// 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_
......@@ -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);
......
......@@ -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);
......
// 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_
// 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
// 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_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment