summaryrefslogtreecommitdiffstats
path: root/mojo/examples/window_manager
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-26 23:04:48 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-26 23:04:48 +0000
commit9af75ae293d6be1ffc437ac6f3849b2e85392213 (patch)
tree37b29dd712223818ebbb5a46db1af3ba9389e1fd /mojo/examples/window_manager
parentc71cec271e6ed56ba166c47a752122f46fa93970 (diff)
downloadchromium_src-9af75ae293d6be1ffc437ac6f3849b2e85392213.zip
chromium_src-9af75ae293d6be1ffc437ac6f3849b2e85392213.tar.gz
chromium_src-9af75ae293d6be1ffc437ac6f3849b2e85392213.tar.bz2
Stop creating colored squares on deadspace click.
Move that feature to a button in the panel since it (kinda) shows push-state style navigation. BUG= R=sky@chromium.org Review URL: https://codereview.chromium.org/356943003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280151 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/examples/window_manager')
-rw-r--r--mojo/examples/window_manager/debug_panel.cc35
-rw-r--r--mojo/examples/window_manager/debug_panel.h32
-rw-r--r--mojo/examples/window_manager/window_manager.cc42
3 files changed, 68 insertions, 41 deletions
diff --git a/mojo/examples/window_manager/debug_panel.cc b/mojo/examples/window_manager/debug_panel.cc
index 53badfa..866c1bd 100644
--- a/mojo/examples/window_manager/debug_panel.cc
+++ b/mojo/examples/window_manager/debug_panel.cc
@@ -4,11 +4,13 @@
#include "mojo/examples/window_manager/debug_panel.h"
+#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "mojo/services/public/cpp/view_manager/node.h"
#include "mojo/views/native_widget_view_manager.h"
#include "ui/gfx/text_constants.h"
#include "ui/views/background.h"
+#include "ui/views/controls/button/blue_button.h"
#include "ui/views/controls/button/radio_button.h"
#include "ui/views/widget/widget.h"
@@ -22,15 +24,20 @@ const int kNavigationTargetGroupId = 1;
} // namespace
-DebugPanel::DebugPanel(view_manager::Node* node)
- : navigation_target_label_(new views::Label(
+DebugPanel::DebugPanel(Delegate* delegate, view_manager::Node* node)
+ : delegate_(delegate),
+ node_(node),
+ navigation_target_label_(new views::Label(
base::ASCIIToUTF16("Navigation target:"))),
navigation_target_new_(new views::RadioButton(
base::ASCIIToUTF16("New window"), kNavigationTargetGroupId)),
navigation_target_source_(new views::RadioButton(
base::ASCIIToUTF16("Source window"), kNavigationTargetGroupId)),
navigation_target_default_(new views::RadioButton(
- base::ASCIIToUTF16("Default"), kNavigationTargetGroupId)) {
+ base::ASCIIToUTF16("Default"), kNavigationTargetGroupId)),
+ next_color_(0),
+ colored_square_(new views::BlueButton(
+ this, base::ASCIIToUTF16("Local nav test"))) {
navigation_target_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
navigation_target_default_->SetChecked(true);
@@ -41,6 +48,7 @@ DebugPanel::DebugPanel(view_manager::Node* node)
widget_delegate->GetContentsView()->AddChildView(navigation_target_default_);
widget_delegate->GetContentsView()->AddChildView(navigation_target_new_);
widget_delegate->GetContentsView()->AddChildView(navigation_target_source_);
+ widget_delegate->GetContentsView()->AddChildView(colored_square_);
widget_delegate->GetContentsView()->SetLayoutManager(this);
views::Widget* widget = new views::Widget();
@@ -87,6 +95,27 @@ void DebugPanel::Layout(views::View* view) {
radios[i]->GetPreferredSize().height());
y += radios[i]->height();
}
+
+ y += kControlBorderInset;
+ colored_square_->SetBounds(kControlBorderInset, y, w,
+ colored_square_->GetPreferredSize().height());
+ y += colored_square_->height();
+}
+
+void DebugPanel::ButtonPressed(views::Button* sender, const ui::Event& event) {
+ std::string url;
+ if (sender == colored_square_) {
+ url = base::StringPrintf(
+ "mojo://mojo_embedded_app/%x",
+ kColors[next_color_ % arraysize(kColors)]);
+ next_color_++;
+ }
+
+ DCHECK(!url.empty());
+ navigation::NavigationDetailsPtr details(
+ navigation::NavigationDetails::New());
+ details->url = url;
+ delegate_->RequestNavigate(node_->id(), navigation::NEW_NODE, details.Pass());
}
} // namespace examples
diff --git a/mojo/examples/window_manager/debug_panel.h b/mojo/examples/window_manager/debug_panel.h
index 4900d32..88a643b 100644
--- a/mojo/examples/window_manager/debug_panel.h
+++ b/mojo/examples/window_manager/debug_panel.h
@@ -5,7 +5,11 @@
#ifndef MOJO_EXAMPLES_WINDOW_MANAGER_DEBUG_PANEL_H_
#define MOJO_EXAMPLES_WINDOW_MANAGER_DEBUG_PANEL_H_
+#include <string>
+
+#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
+#include "ui/views/controls/button/button.h"
#include "ui/views/layout/layout_manager.h"
#include "ui/views/widget/widget_delegate.h"
@@ -22,11 +26,27 @@ class Node;
namespace examples {
+namespace {
+const SkColor kColors[] = { SK_ColorYELLOW,
+ SK_ColorRED,
+ SK_ColorGREEN,
+ SK_ColorMAGENTA };
+}
+
// A panel of controls intended to demonstrate the functionality of the window
// manager.
-class DebugPanel : public views::LayoutManager {
+class DebugPanel : public views::LayoutManager, public views::ButtonListener {
public:
- DebugPanel(view_manager::Node* node);
+ class Delegate {
+ public:
+ virtual void RequestNavigate(
+ uint32 source_node_id, navigation::Target target,
+ navigation::NavigationDetailsPtr nav_details) = 0;
+ protected:
+ virtual ~Delegate(){}
+ };
+
+ DebugPanel(Delegate* delegate, view_manager::Node* node);
virtual ~DebugPanel();
navigation::Target navigation_target() const;
@@ -35,12 +55,20 @@ class DebugPanel : public views::LayoutManager {
// LayoutManager overrides:
virtual gfx::Size GetPreferredSize(const views::View* view) const OVERRIDE;
virtual void Layout(views::View* host) OVERRIDE;
+ virtual void ButtonPressed(views::Button* sender,
+ const ui::Event& event) OVERRIDE;
+
+ Delegate* delegate_;
+ view_manager::Node* node_;
views::Label* navigation_target_label_;
views::RadioButton* navigation_target_new_;
views::RadioButton* navigation_target_source_;
views::RadioButton* navigation_target_default_;
+ size_t next_color_;
+ views::Button* colored_square_;
+
DISALLOW_COPY_AND_ASSIGN(DebugPanel);
};
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc
index 2ac4505..047756b 100644
--- a/mojo/examples/window_manager/window_manager.cc
+++ b/mojo/examples/window_manager/window_manager.cc
@@ -4,7 +4,6 @@
#include "base/basictypes.h"
#include "base/bind.h"
-#include "base/strings/stringprintf.h"
#include "mojo/examples/keyboard/keyboard.mojom.h"
#include "mojo/examples/window_manager/debug_panel.h"
#include "mojo/examples/window_manager/window_manager.mojom.h"
@@ -46,11 +45,6 @@ class WindowManager;
namespace {
-const SkColor kColors[] = { SK_ColorYELLOW,
- SK_ColorRED,
- SK_ColorGREEN,
- SK_ColorMAGENTA };
-
const int kBorderInset = 25;
const int kControlPanelWidth = 200;
const int kTextfieldHeight = 25;
@@ -163,6 +157,7 @@ class KeyboardManager : public KeyboardClient {
};
class WindowManager : public ApplicationDelegate,
+ public DebugPanel::Delegate,
public ViewObserver,
public ViewManagerDelegate,
public ViewEventDispatcher {
@@ -170,8 +165,7 @@ class WindowManager : public ApplicationDelegate,
WindowManager()
: launcher_ui_(NULL),
view_manager_(NULL),
- app_(NULL),
- next_color_(0) {
+ app_(NULL) {
}
virtual ~WindowManager() {}
@@ -216,10 +210,11 @@ class WindowManager : public ApplicationDelegate,
<< " url: " << url.To<std::string>();
}
- void RequestNavigate(
+ // Overridden from DebugPanel::Delegate:
+ virtual void RequestNavigate(
uint32 source_node_id,
navigation::Target target,
- navigation::NavigationDetailsPtr nav_details) {
+ navigation::NavigationDetailsPtr nav_details) OVERRIDE {
launcher_->Launch(nav_details->url,
base::Bind(&WindowManager::OnLaunch,
base::Unretained(this),
@@ -243,30 +238,6 @@ class WindowManager : public ApplicationDelegate,
return true;
}
- // Overridden from ViewObserver:
- virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE {
- // TODO(aa): Replace this with buttons in the control panel.
- if (event->action == ui::ET_MOUSE_RELEASED) {
- std::string app_url;
- if (event->flags & ui::EF_LEFT_MOUSE_BUTTON)
- app_url = "mojo://mojo_embedded_app";
- else if (event->flags & ui::EF_RIGHT_MOUSE_BUTTON)
- app_url = "mojo://mojo_nesting_app";
- if (app_url.empty())
- return;
-
- navigation::NavigationDetailsPtr nav_details(
- navigation::NavigationDetails::New());
- nav_details->url = base::StringPrintf(
- "%s/%x", app_url.c_str(),
- kColors[next_color_ % arraysize(kColors)]);
- next_color_++;
-
- RequestNavigate(content_node_id_, navigation::DEFAULT,
- nav_details.Pass());
- }
- }
-
// Overridden from ViewManagerDelegate:
virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE {
DCHECK(!view_manager_);
@@ -410,7 +381,7 @@ class WindowManager : public ApplicationDelegate,
kTextfieldHeight);
node->SetBounds(bounds);
- debug_panel_ = new DebugPanel(node);
+ debug_panel_ = new DebugPanel(this, node);
}
scoped_ptr<ViewsInit> views_init_;
@@ -425,7 +396,6 @@ class WindowManager : public ApplicationDelegate,
scoped_ptr<KeyboardManager> keyboard_manager_;
ApplicationImpl* app_;
- size_t next_color_;
DISALLOW_COPY_AND_ASSIGN(WindowManager);
};