Chromium Code Reviews| 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..89c6172d23f990e87d73ba9820e7dc4f2fc22e4d 100644 |
| --- a/mandoline/ui/desktop_ui/browser_window.cc |
| +++ b/mandoline/ui/desktop_ui/browser_window.cc |
| @@ -21,10 +21,74 @@ |
| #include "ui/gfx/canvas.h" |
| #include "ui/views/background.h" |
| #include "ui/views/controls/button/label_button.h" |
| +#include "ui/views/layout/grid_layout.h" |
| #include "ui/views/widget/widget_delegate.h" |
| namespace mandoline { |
| +using views::GridLayout; |
| + |
| +class BrowserWindow::ToolbarView : public views::View, |
| + public views::ButtonListener { |
| + public: |
| + ToolbarView(BrowserWindow* browser_window) |
| + : browser_window_(browser_window), |
| + layout_(new views::GridLayout(this)), |
| + back_button_(new views::LabelButton(this, base::ASCIIToUTF16("Back"))), |
|
msw
2015/09/04 22:05:00
lol, "Back" string...
|
| + forward_button_( |
| + new views::LabelButton(this, base::ASCIIToUTF16("Forward"))), |
| + omnibox_launcher_( |
| + new views::LabelButton(this, base::ASCIIToUTF16("Open Omnibox"))) { |
| + SetLayoutManager(layout_); |
|
msw
2015/09/04 22:05:00
BoxLayout might be simpler, I think it's got some
Elliot Glaysher
2015/09/04 22:54:48
Switched to BoxLayout.
|
| + |
| + views::ColumnSet* columns = layout_->AddColumnSet(0); |
| + columns->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, |
| + GridLayout::USE_PREF, 0, 0); |
| + columns->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, |
| + GridLayout::USE_PREF, 0, 0); |
| + columns->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| + GridLayout::USE_PREF, 0, 0); |
| + |
| + layout_->StartRow(0, 0); |
| + layout_->AddView(back_button_); |
| + layout_->AddView(forward_button_); |
| + layout_->AddView(omnibox_launcher_); |
| + } |
| + |
| + ~ToolbarView() override {} |
| + |
| + void SetOmniboxText(const base::string16& text) { |
| + omnibox_launcher_->SetText(text); |
| + } |
| + |
| + void SetBackForwardEnabled(bool back_enabled, bool forward_enabled) { |
|
msw
2015/09/04 22:05:00
nit: "backward" in function and arg name to match
|
| + 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::GridLayout* 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 +135,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 +212,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 +259,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 +286,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 +313,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 +339,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 +361,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 +378,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 +413,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)); |