diff options
Diffstat (limited to 'mandoline/ui')
-rw-r--r-- | mandoline/ui/desktop_ui/BUILD.gn | 2 | ||||
-rw-r--r-- | mandoline/ui/desktop_ui/browser_commands.h | 2 | ||||
-rw-r--r-- | mandoline/ui/desktop_ui/browser_window.cc | 95 | ||||
-rw-r--r-- | mandoline/ui/desktop_ui/browser_window.h | 21 | ||||
-rw-r--r-- | mandoline/ui/desktop_ui/toolbar_view.cc | 55 | ||||
-rw-r--r-- | mandoline/ui/desktop_ui/toolbar_view.h | 45 | ||||
-rw-r--r-- | mandoline/ui/phone_ui/phone_browser_application_delegate.cc | 7 | ||||
-rw-r--r-- | mandoline/ui/phone_ui/phone_browser_application_delegate.h | 2 |
8 files changed, 175 insertions, 54 deletions
diff --git a/mandoline/ui/desktop_ui/BUILD.gn b/mandoline/ui/desktop_ui/BUILD.gn index 6b41cf8..578032c 100644 --- a/mandoline/ui/desktop_ui/BUILD.gn +++ b/mandoline/ui/desktop_ui/BUILD.gn @@ -27,6 +27,8 @@ source_set("lib") { "browser_manager.h", "browser_window.cc", "browser_window.h", + "toolbar_view.cc", + "toolbar_view.h", ] deps = [ diff --git a/mandoline/ui/desktop_ui/browser_commands.h b/mandoline/ui/desktop_ui/browser_commands.h index ab3586e..3ae2ae5 100644 --- a/mandoline/ui/desktop_ui/browser_commands.h +++ b/mandoline/ui/desktop_ui/browser_commands.h @@ -11,6 +11,8 @@ enum class BrowserCommand : uint32_t { CLOSE, FOCUS_OMNIBOX, NEW_WINDOW, + GO_BACK, + GO_FORWARD, }; } // namespace mandoline diff --git a/mandoline/ui/desktop_ui/browser_window.cc b/mandoline/ui/desktop_ui/browser_window.cc index d849752..a62299e 100644 --- a/mandoline/ui/desktop_ui/browser_window.cc +++ b/mandoline/ui/desktop_ui/browser_window.cc @@ -14,6 +14,7 @@ #include "mandoline/ui/desktop_ui/browser_commands.h" #include "mandoline/ui/desktop_ui/browser_manager.h" #include "mandoline/ui/desktop_ui/public/interfaces/omnibox.mojom.h" +#include "mandoline/ui/desktop_ui/toolbar_view.h" #include "mojo/common/common_type_converters.h" #include "mojo/converters/geometry/geometry_type_converters.h" #include "mojo/services/tracing/public/cpp/switches.h" @@ -71,7 +72,7 @@ BrowserWindow::BrowserWindow(mojo::ApplicationImpl* app, : app_(app), host_client_binding_(this), manager_(manager), - omnibox_launcher_(nullptr), + toolbar_view_(nullptr), progress_bar_(nullptr), root_(nullptr), content_(nullptr), @@ -107,6 +108,31 @@ void BrowserWindow::Close() { delete this; } +void BrowserWindow::ShowOmnibox() { + if (!omnibox_.get()) { + mojo::URLRequestPtr request(mojo::URLRequest::New()); + request->url = mojo::String::From("mojo:omnibox"); + omnibox_connection_ = app_->ConnectToApplication(request.Pass()); + omnibox_connection_->AddService<ViewEmbedder>(this); + omnibox_connection_->ConnectToService(&omnibox_); + omnibox_connection_->SetRemoteServiceProviderConnectionErrorHandler( + [this]() { + // This will cause the connection to be re-established the next time + // we come through this codepath. + omnibox_.reset(); + }); + } + omnibox_->ShowForURL(mojo::String::From(current_url_.spec())); +} + +void BrowserWindow::GoBack() { + web_view_.web_view()->GoBack(); +} + +void BrowserWindow::GoForward() { + web_view_.web_view()->GoForward(); +} + BrowserWindow::~BrowserWindow() { DCHECK(!root_); manager_->BrowserWindowClosed(this); @@ -146,6 +172,10 @@ void BrowserWindow::OnEmbed(mojo::View* root) { mojo::KEYBOARD_CODE_L, mojo::EVENT_FLAGS_CONTROL_DOWN); host_->AddAccelerator(static_cast<uint32_t>(BrowserCommand::NEW_WINDOW), mojo::KEYBOARD_CODE_N, mojo::EVENT_FLAGS_CONTROL_DOWN); + host_->AddAccelerator(static_cast<uint32_t>(BrowserCommand::GO_BACK), + mojo::KEYBOARD_CODE_LEFT, mojo::EVENT_FLAGS_ALT_DOWN); + host_->AddAccelerator(static_cast<uint32_t>(BrowserCommand::GO_FORWARD), + mojo::KEYBOARD_CODE_RIGHT, mojo::EVENT_FLAGS_ALT_DOWN); // Now that we're ready, load the default url. LoadURL(default_url_); @@ -189,6 +219,12 @@ void BrowserWindow::OnAccelerator(uint32_t id, mojo::EventPtr event) { case BrowserCommand::FOCUS_OMNIBOX: ShowOmnibox(); break; + case BrowserCommand::GO_BACK: + GoBack(); + break; + case BrowserCommand::GO_FORWARD: + GoForward(); + break; default: NOTREACHED(); break; @@ -210,6 +246,14 @@ void BrowserWindow::ProgressChanged(double progress) { progress_bar_->SetProgress(progress); } +void BrowserWindow::BackForwardChanged( + web_view::mojom::ButtonState back_button, + web_view::mojom::ButtonState forward_button) { + toolbar_view_->SetBackForwardEnabled( + back_button == web_view::mojom::ButtonState::BUTTON_STATE_ENABLED, + forward_button == web_view::mojom::ButtonState::BUTTON_STATE_ENABLED); +} + void BrowserWindow::TitleChanged(const mojo::String& title) { base::string16 formatted = title.is_null() ? base::ASCIIToUTF16("Untitled") @@ -232,7 +276,7 @@ void BrowserWindow::Embed(mojo::URLRequestPtr request) { bool changed = current_url_ != gurl; current_url_ = gurl; if (changed) - omnibox_launcher_->SetText(base::UTF8ToUTF16(current_url_.spec())); + toolbar_view_->SetOmniboxText(base::UTF8ToUTF16(current_url_.spec())); web_view_.web_view()->LoadRequest(request.Pass()); } @@ -258,17 +302,13 @@ void BrowserWindow::Layout(views::View* host) { float inverse_device_pixel_ratio = 1.0f / root_->viewport_metrics().device_pixel_ratio; - gfx::Rect omnibox_launcher_bounds = gfx::ScaleToEnclosingRect( + gfx::Rect toolbar_bounds = gfx::ScaleToEnclosingRect( bounds_in_physical_pixels, inverse_device_pixel_ratio); - omnibox_launcher_bounds.Inset(10, 10, 10, - omnibox_launcher_bounds.height() - 40); - omnibox_launcher_->SetBoundsRect(omnibox_launcher_bounds); + toolbar_bounds.Inset(10, 10, 10, toolbar_bounds.height() - 40); + toolbar_view_->SetBoundsRect(toolbar_bounds); - gfx::Rect progress_bar_bounds(omnibox_launcher_bounds.x(), - omnibox_launcher_bounds.bottom() + 2, - omnibox_launcher_bounds.width(), - 5); - progress_bar_->SetBoundsRect(progress_bar_bounds); + gfx::Rect progress_bar_bounds(toolbar_bounds.x(), toolbar_bounds.bottom() + 2, + toolbar_bounds.width(), 5); // The content view bounds are in physical pixels. mojo::Rect content_bounds_mojo; @@ -283,16 +323,6 @@ void BrowserWindow::Layout(views::View* host) { omnibox_view_->SetBounds( mojo::TypeConverter<mojo::Rect, gfx::Rect>::Convert( bounds_in_physical_pixels)); - -} - -//////////////////////////////////////////////////////////////////////////////// -// BrowserWindow, views::ButtonListener implementation: - -void BrowserWindow::ButtonPressed(views::Button* sender, - const ui::Event& event) { - DCHECK_EQ(sender, omnibox_launcher_); - ShowOmnibox(); } //////////////////////////////////////////////////////////////////////////////// @@ -310,11 +340,9 @@ void BrowserWindow::Init(mojo::View* root) { views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView; widget_delegate->GetContentsView()->set_background( views::Background::CreateSolidBackground(0xFFDDDDDD)); - omnibox_launcher_ = - new views::LabelButton(this, base::ASCIIToUTF16("Open Omnibox")); + toolbar_view_ = new ToolbarView(this); progress_bar_ = new ProgressView; - - widget_delegate->GetContentsView()->AddChildView(omnibox_launcher_); + widget_delegate->GetContentsView()->AddChildView(toolbar_view_); widget_delegate->GetContentsView()->AddChildView(progress_bar_); widget_delegate->GetContentsView()->SetLayoutManager(this); @@ -330,23 +358,6 @@ void BrowserWindow::Init(mojo::View* root) { root_->SetFocus(); } -void BrowserWindow::ShowOmnibox() { - if (!omnibox_.get()) { - mojo::URLRequestPtr request(mojo::URLRequest::New()); - request->url = mojo::String::From("mojo:omnibox"); - omnibox_connection_ = app_->ConnectToApplication(request.Pass()); - omnibox_connection_->AddService<ViewEmbedder>(this); - omnibox_connection_->ConnectToService(&omnibox_); - omnibox_connection_->SetRemoteServiceProviderConnectionErrorHandler( - [this]() { - // This will cause the connection to be re-established the next time - // we come through this codepath. - omnibox_.reset(); - }); - } - omnibox_->ShowForURL(mojo::String::From(current_url_.spec())); -} - void BrowserWindow::EmbedOmnibox() { mojo::ViewTreeClientPtr view_tree_client; omnibox_->GetViewTreeClient(GetProxy(&view_tree_client)); diff --git a/mandoline/ui/desktop_ui/browser_window.h b/mandoline/ui/desktop_ui/browser_window.h index 85b1f33..c2ff8de 100644 --- a/mandoline/ui/desktop_ui/browser_window.h +++ b/mandoline/ui/desktop_ui/browser_window.h @@ -15,7 +15,6 @@ #include "mandoline/ui/desktop_ui/public/interfaces/view_embedder.mojom.h" #include "mojo/application/public/cpp/interface_factory.h" #include "mojo/common/weak_binding_set.h" -#include "ui/views/controls/button/button.h" #include "ui/views/layout/layout_manager.h" #include "url/gurl.h" @@ -25,22 +24,18 @@ class Shell; class View; } -namespace views { -class LabelButton; -} - namespace mandoline { class BrowserManager; class ProgressView; +class ToolbarView; class BrowserWindow : public mojo::ViewTreeDelegate, public mojo::ViewTreeHostClient, public web_view::mojom::WebViewClient, public ViewEmbedder, public mojo::InterfaceFactory<ViewEmbedder>, - public views::LayoutManager, - public views::ButtonListener { + public views::LayoutManager { public: BrowserWindow(mojo::ApplicationImpl* app, mojo::ViewTreeHostFactory* host_factory, @@ -49,6 +44,10 @@ class BrowserWindow : public mojo::ViewTreeDelegate, void LoadURL(const GURL& url); void Close(); + void ShowOmnibox(); + void GoBack(); + void GoForward(); + private: ~BrowserWindow() override; @@ -65,6 +64,8 @@ class BrowserWindow : public mojo::ViewTreeDelegate, void TopLevelNavigate(mojo::URLRequestPtr request) override; void LoadingStateChanged(bool is_loading) override; void ProgressChanged(double progress) override; + void BackForwardChanged(web_view::mojom::ButtonState back_button, + web_view::mojom::ButtonState forward_button) override; void TitleChanged(const mojo::String& title) override; // Overridden from ViewEmbedder: @@ -79,11 +80,7 @@ class BrowserWindow : public mojo::ViewTreeDelegate, gfx::Size GetPreferredSize(const views::View* view) const override; void Layout(views::View* host) override; - // Overridden from views::ButtonListener: - void ButtonPressed(views::Button* sender, const ui::Event& event) override; - void Init(mojo::View* root); - void ShowOmnibox(); void EmbedOmnibox(); mojo::ApplicationImpl* app_; @@ -91,7 +88,7 @@ class BrowserWindow : public mojo::ViewTreeDelegate, mojo::ViewTreeHostPtr host_; mojo::Binding<ViewTreeHostClient> host_client_binding_; BrowserManager* manager_; - views::LabelButton* omnibox_launcher_; + ToolbarView* toolbar_view_; ProgressView* progress_bar_; mojo::View* root_; mojo::View* content_; diff --git a/mandoline/ui/desktop_ui/toolbar_view.cc b/mandoline/ui/desktop_ui/toolbar_view.cc new file mode 100644 index 0000000..764c5cd --- /dev/null +++ b/mandoline/ui/desktop_ui/toolbar_view.cc @@ -0,0 +1,55 @@ +// 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/desktop_ui/toolbar_view.h" + +#include "base/strings/string16.h" +#include "base/strings/utf_string_conversions.h" +#include "mandoline/ui/desktop_ui/browser_window.h" +#include "ui/views/layout/box_layout.h" + +namespace mandoline { + +ToolbarView::ToolbarView(BrowserWindow* browser_window) + : browser_window_(browser_window), + layout_(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 5)), + back_button_(new views::LabelButton(this, base::ASCIIToUTF16("Back"))), + forward_button_( + new views::LabelButton(this, base::ASCIIToUTF16("Forward"))), + omnibox_launcher_( + new views::LabelButton(this, base::ASCIIToUTF16("Open Omnibox"))) { + SetLayoutManager(layout_); + + AddChildView(back_button_); + AddChildView(forward_button_); + AddChildView(omnibox_launcher_); + + layout_->SetDefaultFlex(0); + layout_->SetFlexForView(omnibox_launcher_, 1); +} + +ToolbarView::~ToolbarView() {} + +void ToolbarView::SetOmniboxText(const base::string16& text) { + omnibox_launcher_->SetText(text); +} + +void ToolbarView::SetBackForwardEnabled(bool back_enabled, + bool forward_enabled) { + back_button_->SetEnabled(back_enabled); + forward_button_->SetEnabled(forward_enabled); +} + +void ToolbarView::ButtonPressed(views::Button* sender, const ui::Event& event) { + if (sender == omnibox_launcher_) + browser_window_->ShowOmnibox(); + else if (sender == back_button_) + browser_window_->GoBack(); + else if (sender == forward_button_) + browser_window_->GoForward(); + else + NOTREACHED(); +} + +} // namespace mandoline diff --git a/mandoline/ui/desktop_ui/toolbar_view.h b/mandoline/ui/desktop_ui/toolbar_view.h new file mode 100644 index 0000000..d67ae73 --- /dev/null +++ b/mandoline/ui/desktop_ui/toolbar_view.h @@ -0,0 +1,45 @@ +// 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_DESKTOP_UI_TOOLBAR_VIEW_H_ +#define MANDOLINE_UI_DESKTOP_UI_TOOLBAR_VIEW_H_ + +#include "ui/views/view.h" +#include "ui/views/controls/button/label_button.h" + +namespace views { +class BoxLayout; +class LabelButton; +} + +namespace mandoline { +class BrowserWindow; + +class ToolbarView : public views::View, + public views::ButtonListener { + public: + ToolbarView(BrowserWindow* browser_window); + ~ToolbarView() override; + + // Sets the state of the visual elements. + void SetOmniboxText(const base::string16& text); + void SetBackForwardEnabled(bool back_enabled, bool forward_enabled); + + // Overridden from views::ButtonListener: + void ButtonPressed(views::Button* sender, const ui::Event& event) override; + + private: + BrowserWindow* browser_window_; + + views::BoxLayout* layout_; + views::LabelButton* back_button_; + views::LabelButton* forward_button_; + views::LabelButton* omnibox_launcher_; + + DISALLOW_COPY_AND_ASSIGN(ToolbarView); +}; + +} // namespace mandoline + +#endif // MANDOLINE_UI_DESKTOP_UI_TOOLBAR_VIEW_H_ diff --git a/mandoline/ui/phone_ui/phone_browser_application_delegate.cc b/mandoline/ui/phone_ui/phone_browser_application_delegate.cc index b43910c..93307aa 100644 --- a/mandoline/ui/phone_ui/phone_browser_application_delegate.cc +++ b/mandoline/ui/phone_ui/phone_browser_application_delegate.cc @@ -115,6 +115,13 @@ void PhoneBrowserApplicationDelegate::ProgressChanged(double progress) { // ... } + +void PhoneBrowserApplicationDelegate::BackForwardChanged( + web_view::mojom::ButtonState back_button, + web_view::mojom::ButtonState forward_button) { + // ... +} + void PhoneBrowserApplicationDelegate::TitleChanged(const mojo::String& title) { // ... } diff --git a/mandoline/ui/phone_ui/phone_browser_application_delegate.h b/mandoline/ui/phone_ui/phone_browser_application_delegate.h index cca1bfc..bb41044 100644 --- a/mandoline/ui/phone_ui/phone_browser_application_delegate.h +++ b/mandoline/ui/phone_ui/phone_browser_application_delegate.h @@ -57,6 +57,8 @@ class PhoneBrowserApplicationDelegate : void TopLevelNavigate(mojo::URLRequestPtr request) override; void LoadingStateChanged(bool is_loading) override; void ProgressChanged(double progress) override; + void BackForwardChanged(web_view::mojom::ButtonState back_button, + web_view::mojom::ButtonState forward_button) override; void TitleChanged(const mojo::String& title) override; // Overridden from mojo::InterfaceFactory<LaunchHandler>: |