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

Unified Diff: chrome/browser/chromeos/main_menu.cc

Issue 219037: Changes the main menu to do the following:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 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
Index: chrome/browser/chromeos/main_menu.cc
===================================================================
--- chrome/browser/chromeos/main_menu.cc (revision 27065)
+++ chrome/browser/chromeos/main_menu.cc (working copy)
@@ -5,12 +5,14 @@
#include "chrome/browser/chromeos/main_menu.h"
#include "app/resource_bundle.h"
+#include "base/message_loop.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_view_host_factory.h"
#include "chrome/browser/renderer_host/render_widget_host_view.h"
#include "chrome/browser/renderer_host/render_widget_host_view_gtk.h"
#include "chrome/browser/renderer_host/site_instance.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
#include "grit/app_resources.h"
#include "grit/generated_resources.h"
@@ -31,23 +33,20 @@
(new MainMenu(browser))->ShowImpl();
}
+MainMenu::~MainMenu() {
+ popup_->Close();
+ menu_rvh_->Shutdown();
+}
+
MainMenu::MainMenu(Browser* browser)
: browser_(browser),
popup_(NULL),
site_instance_(NULL),
menu_rvh_(NULL),
rwhv_(NULL),
- child_rvh_(NULL) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(tab_contents_delegate_(this)) {
}
-MainMenu::~MainMenu() {
- gdk_pointer_ungrab(GDK_CURRENT_TIME);
- popup_->Close();
- menu_rvh_->Shutdown();
- if (child_rvh_)
- child_rvh_->Shutdown();
-}
-
void MainMenu::ShowImpl() {
SkBitmap* drop_down_image = ResourceBundle::GetSharedInstance().
GetBitmapNamed(IDR_MAIN_MENU_BUTTON_DROP_DOWN);
@@ -84,14 +83,35 @@
g_signal_connect(rwhv_widget, "button-press-event",
G_CALLBACK(CallButtonPressEvent), this);
// Do a mouse grab on the renderer widget host view's widget so that we can
- // close the popup if the user clicks anywhere else.
+ // close the popup if the user clicks anywhere else. And do a keyboard
+ // grab so that we get all key events.
gdk_pointer_grab(rwhv_widget->window, FALSE,
static_cast<GdkEventMask>(
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK),
NULL, NULL, GDK_CURRENT_TIME);
+ gdk_keyboard_grab(rwhv_widget->window, FALSE, GDK_CURRENT_TIME);
}
+void MainMenu::Delete(bool now) {
+ gdk_keyboard_ungrab(GDK_CURRENT_TIME);
+ gdk_pointer_ungrab(GDK_CURRENT_TIME);
+ // Hide the popup immediately. We don't close it as it contains the
+ // renderwidgethostview, which hasn't been shutdown yet.
+ popup_->Hide();
+ if (now)
+ delete this;
+ else
+ MessageLoop::current()->DeleteSoon(FROM_HERE, this);
+}
+
+// static
+gboolean MainMenu::CallButtonPressEvent(GtkWidget* widget,
+ GdkEventButton* event,
+ MainMenu* menu) {
+ return menu->OnButtonPressEvent(widget, event);
+}
+
gboolean MainMenu::OnButtonPressEvent(GtkWidget* widget,
GdkEventButton* event) {
if (event->x < 0 || event->y < 0 ||
@@ -99,27 +119,46 @@
event->y >= widget->allocation.height) {
// The user clicked outside the bounds of the menu, delete the main which
// results in closing it.
- delete this;
+ Delete(true);
}
return FALSE;
}
-void MainMenu::RequestOpenURL(const GURL& url,
- const GURL& referrer,
- WindowOpenDisposition disposition) {
- browser_->OpenURL(url, referrer, NEW_FOREGROUND_TAB, PageTransition::LINK);
- delete this;
-}
-
void MainMenu::CreateNewWindow(int route_id,
base::WaitableEvent* modal_dialog_event) {
- if (child_rvh_) {
- // We should never get here. If we do, it indicates a child render view
- // host was created and we didn't get a subsequent RequestOpenURL.
+ if (pending_contents_.get()) {
NOTREACHED();
return;
}
- DCHECK(!child_rvh_);
- child_rvh_ = RenderViewHostFactory::Create(
- site_instance_, this, route_id, modal_dialog_event);
+
+ helper_.CreateNewWindow(route_id, modal_dialog_event, browser_->profile(),
+ site_instance_,
+ DOMUIFactory::GetDOMUIType(GURL(kMenuURL)));
+ pending_contents_.reset(helper_.GetCreatedWindow(route_id));
+ pending_contents_->set_delegate(&tab_contents_delegate_);
}
+
+void MainMenu::ShowCreatedWindow(int route_id,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_pos,
+ bool user_gesture,
+ const GURL& creator_url) {
+ if (disposition == NEW_POPUP) {
+ pending_contents_->set_delegate(NULL);
+ browser_->GetSelectedTabContents()->AddNewContents(
+ pending_contents_.release(), disposition, initial_pos, user_gesture,
+ creator_url);
+ Delete(false);
+ }
+}
+
+void MainMenu::TabContentsDelegateImpl::OpenURLFromTab(
+ TabContents* source,
+ const GURL& url,
+ const GURL& referrer,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition) {
+ menu_->browser_->OpenURL(url, referrer, NEW_FOREGROUND_TAB,
+ PageTransition::LINK);
+ menu_->Delete(true);
+}
« no previous file with comments | « chrome/browser/chromeos/main_menu.h ('k') | chrome/browser/tab_contents/render_view_host_delegate_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698