Index: mandoline/ui/desktop_ui/browser_window.cc |
diff --git a/mandoline/ui/desktop_ui/browser_window.cc b/mandoline/ui/desktop_ui/browser_window.cc |
index 4251a007906b38cac8185a4c9b71bdb746bb23e2..25f102b5ab4e903c576d1efa46e1ce96cea95a12 100644 |
--- a/mandoline/ui/desktop_ui/browser_window.cc |
+++ b/mandoline/ui/desktop_ui/browser_window.cc |
@@ -21,10 +21,66 @@ |
#include "ui/gfx/canvas.h" |
#include "ui/views/background.h" |
#include "ui/views/controls/button/label_button.h" |
+#include "ui/views/layout/box_layout.h" |
#include "ui/views/widget/widget_delegate.h" |
namespace mandoline { |
+class BrowserWindow::ToolbarView : public views::View, |
sky
2015/09/09 20:43:28
Move this into its own file. No doubt it's going t
|
+ public views::ButtonListener { |
+ public: |
+ 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() override {} |
+ |
+ void SetOmniboxText(const base::string16& text) { |
+ omnibox_launcher_->SetText(text); |
+ } |
+ |
+ void SetBackForwardEnabled(bool back_enabled, bool forward_enabled) { |
+ back_button_->SetEnabled(back_enabled); |
+ forward_button_->SetEnabled(forward_enabled); |
+ } |
+ |
+ // Overridden from views::ButtonListener: |
+ void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
+ if (sender == omnibox_launcher_) |
+ browser_window_->ShowOmnibox(); |
+ else if (sender == back_button_) |
+ browser_window_->GoBack(); |
+ else if (sender == forward_button_) |
+ browser_window_->GoForward(); |
+ else |
+ NOTIMPLEMENTED(); |
sky
2015/09/09 20:43:28
Shouldn't this be a NOTREACHED?
|
+ } |
+ |
+ private: |
+ BrowserWindow* browser_window_; |
+ |
+ views::BoxLayout* layout_; |
+ views::LabelButton* back_button_; |
+ views::LabelButton* forward_button_; |
+ views::LabelButton* omnibox_launcher_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ToolbarView); |
+}; |
+ |
class ProgressView : public views::View { |
public: |
ProgressView() : progress_(0.f), loading_(false) {} |
@@ -71,7 +127,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), |
@@ -146,6 +202,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 +249,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 +276,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 +306,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 +332,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::ToEnclosingRect(gfx::ScaleRect(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); |
- |
- gfx::Rect progress_bar_bounds(omnibox_launcher_bounds.x(), |
- omnibox_launcher_bounds.bottom() + 2, |
- omnibox_launcher_bounds.width(), |
- 5); |
+ gfx::Rect toolbar_bounds = gfx::ToEnclosingRect( |
+ gfx::ScaleRect(bounds_in_physical_pixels, inverse_device_pixel_ratio)); |
+ toolbar_bounds.Inset(10, 10, 10, toolbar_bounds.height() - 40); |
+ toolbar_view_->SetBoundsRect(toolbar_bounds); |
+ |
+ gfx::Rect progress_bar_bounds(toolbar_bounds.x(), toolbar_bounds.bottom() + 2, |
+ toolbar_bounds.width(), 5); |
progress_bar_->SetBoundsRect(progress_bar_bounds); |
// The content view bounds are in physical pixels. |
@@ -284,16 +354,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(); |
} |
//////////////////////////////////////////////////////////////////////////////// |
@@ -311,11 +371,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); |
@@ -348,6 +406,14 @@ void BrowserWindow::ShowOmnibox() { |
omnibox_->ShowForURL(mojo::String::From(current_url_.spec())); |
} |
+void BrowserWindow::GoBack() { |
+ web_view_.web_view()->GoBack(); |
+} |
+ |
+void BrowserWindow::GoForward() { |
+ web_view_.web_view()->GoForward(); |
+} |
+ |
void BrowserWindow::EmbedOmnibox() { |
mojo::ViewTreeClientPtr view_tree_client; |
omnibox_->GetViewTreeClient(GetProxy(&view_tree_client)); |