Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Unified Diff: ui/aura_shell/examples/window_type_launcher.cc

Issue 7979021: Adds a trivial menu to WindowTypeLauncher. This was more for me to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/aura_shell/examples/window_type_launcher.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura_shell/examples/window_type_launcher.cc
diff --git a/ui/aura_shell/examples/window_type_launcher.cc b/ui/aura_shell/examples/window_type_launcher.cc
index 7f7d2a193bda7e8ecdf32c24f4f5ee5ca92b1d0d..e240fa2507382a25a9c82b179aa654ddbab05168 100644
--- a/ui/aura_shell/examples/window_type_launcher.cc
+++ b/ui/aura_shell/examples/window_type_launcher.cc
@@ -10,11 +10,24 @@
#include "ui/aura_shell/examples/toplevel_window.h"
#include "ui/gfx/canvas.h"
#include "views/controls/button/text_button.h"
+#include "views/controls/menu/menu_item_view.h"
+#include "views/controls/menu/menu_runner.h"
#include "views/widget/widget.h"
+using views::MenuItemView;
+using views::MenuRunner;
+
namespace aura_shell {
namespace examples {
+void InitWindowTypeLauncher() {
+ views::Widget* widget =
+ views::Widget::CreateWindowWithBounds(new WindowTypeLauncher,
+ gfx::Rect(120, 150, 400, 300));
+ widget->GetNativeView()->set_name(ASCIIToUTF16("WindowTypeLauncher"));
+ widget->Show();
+}
+
WindowTypeLauncher::WindowTypeLauncher()
: ALLOW_THIS_IN_INITIALIZER_LIST(
create_button_(new views::NativeTextButton(this, L"Create Window"))),
@@ -22,6 +35,7 @@ WindowTypeLauncher::WindowTypeLauncher()
new views::NativeTextButton(this, L"Create Pointy Bubble"))) {
AddChildView(create_button_);
AddChildView(bubble_button_);
+ set_context_menu_controller(this);
}
WindowTypeLauncher::~WindowTypeLauncher() {
@@ -48,6 +62,11 @@ gfx::Size WindowTypeLauncher::GetPreferredSize() {
return gfx::Size(300, 500);
}
+bool WindowTypeLauncher::OnMousePressed(const views::MouseEvent& event) {
+ // Overriden so we get OnMouseReleased and can show the context menu.
+ return true;
Ben Goodger (Google) 2011/09/21 16:10:28 Not a comment on this CL per se, but remember the
+}
+
views::View* WindowTypeLauncher::GetContentsView() {
return this;
}
@@ -68,12 +87,21 @@ void WindowTypeLauncher::ButtonPressed(views::Button* sender,
}
}
-void InitWindowTypeLauncher() {
- views::Widget* widget =
- views::Widget::CreateWindowWithBounds(new WindowTypeLauncher,
- gfx::Rect(120, 150, 400, 300));
- widget->GetNativeView()->set_name(ASCIIToUTF16("WindowTypeLauncher"));
- widget->Show();
+void WindowTypeLauncher::ExecuteCommand(int id) {
+ DCHECK_EQ(id, COMMAND_NEW_WINDOW);
+ InitWindowTypeLauncher();
+}
+
+void WindowTypeLauncher::ShowContextMenuForView(views::View* source,
+ const gfx::Point& p,
+ bool is_mouse_gesture) {
+ MenuItemView* root = new MenuItemView(this);
+ root->AppendMenuItem(COMMAND_NEW_WINDOW, L"New Window", MenuItemView::NORMAL);
+ // MenuRunner takes ownership of root.
+ menu_runner_.reset(new MenuRunner(root));
+ menu_runner_->RunMenuAt(
+ GetWidget(), NULL, gfx::Rect(p, gfx::Size(0, 0)),
+ MenuItemView::TOPLEFT, MenuRunner::HAS_MNEMONICS);
}
} // namespace examples
« no previous file with comments | « ui/aura_shell/examples/window_type_launcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698