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 051c264b61b039b51446ef2929166d94a94f0863..d5497de8f9df3d995c42cfec233c30a4c639b737 100644 |
--- a/mandoline/ui/desktop_ui/browser_window.cc |
+++ b/mandoline/ui/desktop_ui/browser_window.cc |
@@ -21,10 +21,68 @@ |
#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 { |
+using views::BoxLayout; |
msw
2015/09/04 23:49:00
nit: remove, inline one more "views::".
|
+ |
+class BrowserWindow::ToolbarView : public views::View, |
+ public views::ButtonListener { |
+ public: |
+ ToolbarView(BrowserWindow* browser_window) |
+ : browser_window_(browser_window), |
+ layout_(new views::BoxLayout(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(); |
+ } |
+ |
+ 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 +129,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), |
@@ -148,6 +206,10 @@ void BrowserWindow::OnEmbed(mojo::View* root) { |
mojo::EVENT_FLAGS_CONTROL_DOWN); |
host_->AddAccelerator(BrowserCommand_NewWindow, mojo::KEYBOARD_CODE_N, |
mojo::EVENT_FLAGS_CONTROL_DOWN); |
+ host_->AddAccelerator(BrowserCommand_GoBack, mojo::KEYBOARD_CODE_LEFT, |
+ mojo::EVENT_FLAGS_ALT_DOWN); |
+ host_->AddAccelerator(BrowserCommand_GoForward, mojo::KEYBOARD_CODE_RIGHT, |
+ mojo::EVENT_FLAGS_ALT_DOWN); |
// Now that we're ready, load the default url. |
LoadURL(default_url_); |
@@ -191,6 +253,12 @@ void BrowserWindow::OnAccelerator(uint32_t id, mojo::EventPtr event) { |
case BrowserCommand_FocusOmnibox: |
ShowOmnibox(); |
break; |
+ case BrowserCommand_GoBack: |
+ GoBack(); |
+ break; |
+ case BrowserCommand_GoForward: |
+ GoForward(); |
+ break; |
default: |
NOTREACHED(); |
break; |
@@ -212,6 +280,11 @@ void BrowserWindow::ProgressChanged(double progress) { |
progress_bar_->SetProgress(progress); |
} |
+void BrowserWindow::BackForwardChanged(bool back_enabled, |
+ bool forward_enabled) { |
+ toolbar_view_->SetBackForwardEnabled(back_enabled, forward_enabled); |
+} |
+ |
void BrowserWindow::TitleChanged(const mojo::String& title) { |
base::string16 formatted = |
title.is_null() ? base::ASCIIToUTF16("Untitled") |
@@ -234,7 +307,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()); |
} |
@@ -260,17 +333,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. |
@@ -286,16 +355,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(); |
} |
//////////////////////////////////////////////////////////////////////////////// |
@@ -313,11 +372,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); |
@@ -350,6 +407,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)); |