summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-11 21:29:50 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-11 21:29:50 +0000
commitc280bfdd4f944ed9c33f4306efa6d388d82a804a (patch)
treeb484c60677240261fbb04a554ac6efb49270e504 /chrome
parent371d04994828cbb44f679f2191bbe515ded93809 (diff)
downloadchromium_src-c280bfdd4f944ed9c33f4306efa6d388d82a804a.zip
chromium_src-c280bfdd4f944ed9c33f4306efa6d388d82a804a.tar.gz
chromium_src-c280bfdd4f944ed9c33f4306efa6d388d82a804a.tar.bz2
Move compact navigation bar('s entry view) to main menu.
* Chagned main menu to use TYPE_WINDOW instead of POPUP. * Added hooks to close main menu when a user clicked non content area. (see MainMenuContainer::OnMousePressed and MainMenu::ActiveWindowChanged) * removed entry view from CompactNavigationBar view. We probably should rename this class (later). * Fixed a mouse coordinates issue in WidgetGtk: A location in the mouse event may not be in its gdk_window when it's originated from child gdk_window. * UIStyle's enum has to start with 0 * removed DLOG thas I checked in by accident. BUG=31766 TEST=manual: switch to compact navigation bar using ctrl-shift-c and confirm that no navigation entry in title bar. main menu has the navigation entry instead. Review URL: http://codereview.chromium.org/604015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38816 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chromeos/browser_view.cc5
-rw-r--r--chrome/browser/chromeos/browser_view.h3
-rw-r--r--chrome/browser/chromeos/compact_location_bar_host.cc1
-rw-r--r--chrome/browser/chromeos/compact_navigation_bar.cc180
-rw-r--r--chrome/browser/chromeos/compact_navigation_bar.h30
-rw-r--r--chrome/browser/chromeos/main_menu.cc325
-rw-r--r--chrome/browser/chromeos/main_menu.h56
7 files changed, 319 insertions, 281 deletions
diff --git a/chrome/browser/chromeos/browser_view.cc b/chrome/browser/chromeos/browser_view.cc
index 5313f63..d689a6e 100644
--- a/chrome/browser/chromeos/browser_view.cc
+++ b/chrome/browser/chromeos/browser_view.cc
@@ -404,8 +404,8 @@ bool BrowserView::IsToolbarVisible() const {
}
void BrowserView::SetFocusToLocationBar() {
- if (compact_navigation_bar_->IsFocusable()) {
- compact_navigation_bar_->FocusLocation();
+ if (is_compact_style()) {
+ ShowCompactLocationBarUnderSelectedTab();
} else {
::BrowserView::SetFocusToLocationBar();
}
@@ -413,7 +413,6 @@ void BrowserView::SetFocusToLocationBar() {
void BrowserView::ToggleCompactNavigationBar() {
ui_style_ = static_cast<UIStyle>((ui_style_ + 1) % 2);
- compact_navigation_bar_->SetFocusable(is_compact_style());
compact_location_bar_host_->SetEnabled(is_compact_style());
compact_location_bar_host_->Hide(false);
Layout();
diff --git a/chrome/browser/chromeos/browser_view.h b/chrome/browser/chromeos/browser_view.h
index a8d0470..dbdc0c2 100644
--- a/chrome/browser/chromeos/browser_view.h
+++ b/chrome/browser/chromeos/browser_view.h
@@ -47,7 +47,7 @@ class BrowserView : public ::BrowserView,
// the tabstrip is moved to the side and the omnibox is moved on top of
// the tabstrip.
enum UIStyle {
- StandardStyle,
+ StandardStyle = 0,
CompactStyle,
SidebarStyle,
};
@@ -133,4 +133,3 @@ class BrowserView : public ::BrowserView,
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_BROWSER_VIEW_H_
-
diff --git a/chrome/browser/chromeos/compact_location_bar_host.cc b/chrome/browser/chromeos/compact_location_bar_host.cc
index 98d4325..48cfc85 100644
--- a/chrome/browser/chromeos/compact_location_bar_host.cc
+++ b/chrome/browser/chromeos/compact_location_bar_host.cc
@@ -59,7 +59,6 @@ class MouseObserver : public MessageLoopForUI::Observer {
// root window's coordinates.
bool HitContentArea(GdkEvent* event) {
gfx::Point p(event->button.x_root, event->button.y_root);
- DLOG(WARNING) << "point:" << p;
// First, exclude the location bar as it's shown on top of
// content area.
if (HitOnScreen(host_->GetClbView(), p)) {
diff --git a/chrome/browser/chromeos/compact_navigation_bar.cc b/chrome/browser/chromeos/compact_navigation_bar.cc
index 6dcbeab..bee7a920 100644
--- a/chrome/browser/chromeos/compact_navigation_bar.cc
+++ b/chrome/browser/chromeos/compact_navigation_bar.cc
@@ -10,12 +10,10 @@
#include "app/theme_provider.h"
#include "base/logging.h"
#include "chrome/app/chrome_dll_resource.h"
-#include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
#include "chrome/browser/back_forward_menu_model.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_theme_provider.h"
#include "chrome/browser/browser_window.h"
-#include "chrome/browser/chromeos/status/status_area_view.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/view_ids.h"
@@ -37,27 +35,18 @@ static const int kInnerPadding = 1;
// Spacing between buttons.
static const int kHorizPadding = 3;
-static const int kURLWidth = 180;
-
// Preferred height.
static const int kPreferredHeight = 25;
-// Draw this much white around the URL bar to make it look larger than it
-// actually is.
-static const int kURLPadding = 2;
-
////////////////////////////////////////////////////////////////////////////////
// CompactNavigationBar public:
CompactNavigationBar::CompactNavigationBar(::BrowserView* browser_view)
: browser_view_(browser_view),
initialized_(false) {
- SetFocusable(true);
}
CompactNavigationBar::~CompactNavigationBar() {
- if (location_entry_view_->native_view())
- location_entry_view_->Detach();
}
void CompactNavigationBar::Init() {
@@ -104,35 +93,11 @@ void CompactNavigationBar::Init() {
views::ImageButton::ALIGN_MIDDLE);
AddChildView(forward_);
- // URL bar construction.
- location_entry_.reset(new AutocompleteEditViewGtk(
- this, browser->toolbar_model(), browser->profile(),
- browser->command_updater(), false, this));
- location_entry_->Init();
- gtk_widget_show_all(location_entry_->widget());
- gtk_widget_hide(location_entry_->widget());
-
- location_entry_view_ = new views::NativeViewHost;
- AddChildView(location_entry_view_);
- location_entry_view_->set_focus_view(this);
- location_entry_view_->Attach(location_entry_->widget());
-
set_background(new ThemeBackground(browser_view_));
}
-void CompactNavigationBar::Focus() {
- location_entry_->SetFocus();
-}
-
-void CompactNavigationBar::FocusLocation() {
- location_entry_->SetFocus();
- location_entry_->SelectAll(true);
-}
-
gfx::Size CompactNavigationBar::GetPreferredSize() {
- int width = 0;
-
- width += kURLWidth + kHorizPadding + kURLPadding * 2; // URL bar.
+ int width = kHorizPadding;
width += back_->GetPreferredSize().width() + kHorizPadding +
kInnerPadding * 2;
width += bf_separator_->GetPreferredSize().width() + kHorizPadding;
@@ -147,49 +112,27 @@ void CompactNavigationBar::Layout() {
if (!initialized_)
return;
- // We hide navigation buttons when the entry has focus. Navigation
- // buttons' visibility is controlled in OnKillFocus/OnSetFocus methods.
- if (!back_->IsVisible()) {
- // Fill the view with the entry view while it has focus.
- location_entry_view_->SetBounds(kURLPadding, 0,
- width() - kHorizPadding, height());
- } else {
- // Layout forward/back buttons after entry views as follows:
- // [Entry View] [Back]|[Forward]
- int curx = 0;
- // URL bar.
- location_entry_view_->SetBounds(curx + kURLPadding, 0,
- kURLWidth + kURLPadding * 2, height());
- curx += kURLWidth + kHorizPadding + kURLPadding * 2;
+ // Layout forward/back buttons after entry views as follows:
+ // [Back]|[Forward]
+ int curx = 0;
+ // "Back | Forward" section.
+ gfx::Size button_size = back_->GetPreferredSize();
+ button_size.set_width(button_size.width() + kInnerPadding * 2);
+ back_->SetBounds(curx, 0, button_size.width(), height());
+ curx += button_size.width() + kHorizPadding;
- // "Back | Forward" section.
- gfx::Size button_size = back_->GetPreferredSize();
- button_size.set_width(button_size.width() + kInnerPadding * 2);
- back_->SetBounds(curx, 0, button_size.width(), height());
- curx += button_size.width() + kHorizPadding;
+ button_size = bf_separator_->GetPreferredSize();
+ bf_separator_->SetBounds(curx, 0, button_size.width(), height());
+ curx += button_size.width() + kHorizPadding;
- button_size = bf_separator_->GetPreferredSize();
- bf_separator_->SetBounds(curx, 0, button_size.width(), height());
- curx += button_size.width() + kHorizPadding;
-
- button_size = forward_->GetPreferredSize();
- button_size.set_width(button_size.width() + kInnerPadding * 2);
- forward_->SetBounds(curx, 0, button_size.width(), height());
- curx += button_size.width() + kHorizPadding;
- }
+ button_size = forward_->GetPreferredSize();
+ button_size.set_width(button_size.width() + kInnerPadding * 2);
+ forward_->SetBounds(curx, 0, button_size.width(), height());
+ curx += button_size.width() + kHorizPadding;
}
void CompactNavigationBar::Paint(gfx::Canvas* canvas) {
PaintBackground(canvas);
-
- // Draw a white box around the edit field so that it looks larger. This is
- // kind of what the default GTK location bar does, although they have a
- // fancier border.
- canvas->FillRectInt(0xFFFFFFFF,
- location_entry_view_->x() - kURLPadding,
- 2,
- location_entry_view_->width() + kURLPadding * 2,
- height() - 5);
}
////////////////////////////////////////////////////////////////////////////////
@@ -197,70 +140,9 @@ void CompactNavigationBar::Paint(gfx::Canvas* canvas) {
void CompactNavigationBar::ButtonPressed(
views::Button* sender, const views::Event& event) {
- int id = sender->tag();
- switch (id) {
- case IDC_BACK:
- case IDC_FORWARD:
- case IDC_RELOAD:
- // Forcibly reset the location bar, since otherwise it won't discard any
- // ongoing user edits, since it doesn't realize this is a user-initiated
- // action.
- location_entry_->RevertAll();
- break;
- }
browser_view_->browser()->ExecuteCommandWithDisposition(
- id, event_utils::DispositionFromEventFlags(sender->mouse_event_flags()));
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// AutocompleteController implementation.
-
-void CompactNavigationBar::OnAutocompleteAccept(
- const GURL& url,
- WindowOpenDisposition disposition,
- PageTransition::Type transition,
- const GURL& alternate_nav_url) {
- AddTabWithURL(url, transition);
-}
-
-void CompactNavigationBar::OnChanged() {
- // Other one does "DoLayout" here.
-}
-
-void CompactNavigationBar::OnInputInProgress(bool in_progress) {
-}
-
-void CompactNavigationBar::OnKillFocus() {
- back_->SetVisible(true);
- bf_separator_->SetVisible(true);
- forward_->SetVisible(true);
- Layout();
- SchedulePaint();
-}
-
-void CompactNavigationBar::OnSetFocus() {
- back_->SetVisible(false);
- bf_separator_->SetVisible(false);
- forward_->SetVisible(false);
- Layout();
- SchedulePaint();
-}
-
-SkBitmap CompactNavigationBar::GetFavIcon() const {
- return SkBitmap();
-}
-
-std::wstring CompactNavigationBar::GetTitle() const {
- return std::wstring();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// BubblePositioner implementation.
-
-gfx::Rect CompactNavigationBar::GetLocationStackBounds() const {
- gfx::Point origin;
- ConvertPointToScreen(this, &origin);
- return gfx::Rect(origin, size());
+ sender->tag(),
+ event_utils::DispositionFromEventFlags(sender->mouse_event_flags()));
}
////////////////////////////////////////////////////////////////////////////////
@@ -276,30 +158,4 @@ void CompactNavigationBar::EnabledStateChangedForCommand(int id, bool enabled) {
}
}
-////////////////////////////////////////////////////////////////////////////////
-// CompactNavigationBar private:
-
-void CompactNavigationBar::AddTabWithURL(const GURL& url,
- PageTransition::Type transition) {
- Browser* browser = browser_view_->browser();
- switch (StatusAreaView::GetOpenTabsMode()) {
- case StatusAreaView::OPEN_TABS_ON_LEFT: {
- // Add the new tab at the first non-pinned location.
- int index = browser->tabstrip_model()->IndexOfFirstNonMiniTab();
- browser->AddTabWithURL(url, GURL(), transition,
- true, index, true, NULL);
- break;
- }
- case StatusAreaView::OPEN_TABS_CLOBBER: {
- browser->GetSelectedTabContents()->controller().LoadURL(
- url, GURL(), transition);
- break;
- }
- case StatusAreaView::OPEN_TABS_ON_RIGHT: {
- browser->AddTabWithURL(url, GURL(), transition, true, -1, true, NULL);
- break;
- }
- }
-}
-
} // namespace chromeos
diff --git a/chrome/browser/chromeos/compact_navigation_bar.h b/chrome/browser/chromeos/compact_navigation_bar.h
index 0e09c4d..3b15826 100644
--- a/chrome/browser/chromeos/compact_navigation_bar.h
+++ b/chrome/browser/chromeos/compact_navigation_bar.h
@@ -7,8 +7,6 @@
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
-#include "chrome/browser/autocomplete/autocomplete_edit.h"
-#include "chrome/browser/bubble_positioner.h"
#include "chrome/browser/command_updater.h"
#include "views/controls/button/button.h"
#include "views/view.h"
@@ -29,8 +27,6 @@ namespace chromeos {
// a small text entry box.
class CompactNavigationBar : public views::View,
public views::ButtonListener,
- public AutocompleteEditController,
- public BubblePositioner,
public CommandUpdater::CommandObserver {
public:
explicit CompactNavigationBar(::BrowserView* browser_view);
@@ -40,41 +36,18 @@ class CompactNavigationBar : public views::View,
// widget.
void Init();
- // Set focus to the location entry in the compact navigation bar.
- void FocusLocation();
-
// views::View overrides.
virtual gfx::Size GetPreferredSize();
virtual void Layout();
virtual void Paint(gfx::Canvas* canvas);
- virtual void Focus();
private:
// views::ButtonListener implementation.
virtual void ButtonPressed(views::Button* sender, const views::Event& event);
- // AutocompleteController implementation.
- virtual void OnAutocompleteAccept(const GURL& url,
- WindowOpenDisposition disposition,
- PageTransition::Type transition,
- const GURL& alternate_nav_url);
- virtual void OnChanged();
- virtual void OnInputInProgress(bool in_progress);
- virtual void OnKillFocus();
- virtual void OnSetFocus();
- virtual SkBitmap GetFavIcon() const;
- virtual std::wstring GetTitle() const;
-
- // BubblePositioner implementation.
- virtual gfx::Rect GetLocationStackBounds() const;
-
// CommandUpdater::CommandObserver implementation.
virtual void EnabledStateChangedForCommand(int id, bool enabled);
- // Add new tab for the given url. The location of new tab is
- // controlled by the method |StatusAreaView::GetOpenTabsMode()|.
- void AddTabWithURL(const GURL& url, PageTransition::Type transition);
-
::BrowserView* browser_view_;
bool initialized_;
@@ -83,9 +56,6 @@ class CompactNavigationBar : public views::View,
views::ImageView* bf_separator_;
views::ImageButton* forward_;
- scoped_ptr<AutocompleteEditViewGtk> location_entry_;
- views::NativeViewHost* location_entry_view_;
-
// History menu for back and forward buttons.
scoped_ptr<BackForwardMenuModel> back_menu_model_;
scoped_ptr<BackForwardMenuModel> forward_menu_model_;
diff --git a/chrome/browser/chromeos/main_menu.cc b/chrome/browser/chromeos/main_menu.cc
index 452f412..6760899 100644
--- a/chrome/browser/chromeos/main_menu.cc
+++ b/chrome/browser/chromeos/main_menu.cc
@@ -7,13 +7,19 @@
#include <string>
#include <vector>
+#include "app/gfx/canvas.h"
#include "app/gfx/insets.h"
#include "app/resource_bundle.h"
#include "base/command_line.h"
#include "base/message_loop.h"
#include "base/string_util.h"
-#include "chrome/browser/browser_list.h"
+#include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_list.h"
+#include "chrome/browser/browser_window.h"
+#include "chrome/browser/bubble_positioner.h"
+#include "chrome/browser/chromeos/browser_view.h"
+#include "chrome/browser/chromeos/status/status_area_view.h"
#include "chrome/browser/in_process_webkit/dom_storage_context.h"
#include "chrome/browser/in_process_webkit/webkit_context.h"
#include "chrome/browser/profile.h"
@@ -23,44 +29,49 @@
#include "chrome/browser/renderer_host/render_widget_host_view_gtk.h"
#include "chrome/browser/renderer_host/site_instance.h"
#include "chrome/browser/renderer_preferences_util.h"
-#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/views/tabs/tab_overview_types.h"
#include "grit/app_resources.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "views/background.h"
+#include "views/controls/native/native_view_host.h"
#include "views/painter.h"
#include "views/screen.h"
#include "views/widget/root_view.h"
#include "views/widget/widget_gtk.h"
-namespace chromeos {
-// Initial size of the renderer. This is contained within a window whose size
-// is set to the size of the image IDR_MAIN_MENU_BUTTON_DROP_DOWN.
-static const int kRendererX = 0;
-static const int kRendererY = 25;
-static const int kRendererWidth = 250;
-static const int kRendererHeight = 400;
+namespace {
+
+// Padding & margins for the navigation entry.
+const int kNavigationEntryPadding = 2;
+const int kNavigationEntryXMargin = 3;
+const int kNavigationEntryYMargin = 1;
+
+// NavigationBar size.
+const int kNavigationBarWidth = 300;
+const int kNavigationBarHeight = 25;
// Insets defining the regions that are stretched and titled to create the
// background of the popup. These constants are fed into
// Painter::CreateImagePainter as the insets, see it for details.
-static const int kBackgroundImageTop = 27;
-static const int kBackgroundImageLeft = 85;
-static const int kBackgroundImageBottom = 10;
-static const int kBackgroundImageRight = 8;
+const int kBackgroundImageTop = 27;
+const int kBackgroundImageLeft = 85;
+const int kBackgroundImageBottom = 10;
+const int kBackgroundImageRight = 8;
// Command line switch for specifying url of the page.
-static const wchar_t kURLSwitch[] = L"main-menu-url";
+const wchar_t kURLSwitch[] = L"main-menu-url";
// Command line switch for specifying the size of the main menu. The default is
// full screen.
-static const wchar_t kMenuSizeSwitch[] = L"main-menu-size";
+const wchar_t kMenuSizeSwitch[] = L"main-menu-size";
// URL of the page to load. This is ignored if kURLSwitch is specified.
-static const char kMenuURL[] = "http://goto.ext.google.com/crux-home";
+const char kMenuURL[] = "http://goto.ext.google.com/crux-home";
// Returns the size of the popup. By default the popup is sized slightly
// larger than full screen, but can be overriden by the command line switch
@@ -83,13 +94,6 @@ static gfx::Size GetPopupSize() {
return size;
}
-// Returns the size for the renderer widget host view given the specified
-// size of the popup.
-static gfx::Size CalculateRWHVSize(const gfx::Size& popup_size) {
- return gfx::Size(popup_size.width() - kRendererX - kBackgroundImageRight,
- popup_size.height() - kRendererY - kBackgroundImageBottom);
-}
-
// Returns the URL of the menu.
static GURL GetMenuURL() {
std::wstring url_string =
@@ -99,6 +103,140 @@ static GURL GetMenuURL() {
return GURL(kMenuURL);
}
+} // namspace
+
+namespace chromeos {
+
+// A navigation bar that is shown in the main menu in
+// compact navigation bar mode.
+class NavigationBar : public views::View,
+ public BubblePositioner {
+ public:
+ explicit NavigationBar(MainMenu* main_menu)
+ : views::View(),
+ main_menu_(main_menu),
+ location_entry_view_(NULL) {
+ SetFocusable(true);
+ location_entry_view_ = new views::NativeViewHost;
+ AddChildView(location_entry_view_);
+ }
+
+ virtual ~NavigationBar() {
+ }
+
+ // views::View overrides.
+ virtual void Focus() {
+ location_entry_->SetFocus();
+ location_entry_->SelectAll(true);
+ }
+
+ virtual void Layout() {
+ const int horizontal_margin =
+ kNavigationEntryPadding + kNavigationEntryYMargin;
+
+ location_entry_view_->SetBounds(
+ kNavigationEntryXMargin + kNavigationEntryPadding, horizontal_margin,
+ kNavigationBarWidth, height() - horizontal_margin * 2);
+ }
+
+ virtual void Paint(gfx::Canvas* canvas) {
+ const int padding = kNavigationEntryPadding;
+ canvas->FillRectInt(SK_ColorWHITE, 0, 0, width(), height());
+ // Draw border around the entry.
+ canvas->DrawRectInt(SK_ColorGRAY,
+ location_entry_view_->x() - padding,
+ location_entry_view_->y() - padding,
+ location_entry_view_->width() + padding * 2,
+ location_entry_view_->height() + padding * 2);
+ }
+
+ // BubblePositioner implementation.
+ virtual gfx::Rect GetLocationStackBounds() const {
+ gfx::Point origin(0, height());
+ views::View::ConvertPointToScreen(this, &origin);
+ return gfx::Rect(origin, gfx::Size(500, 0));
+ }
+
+ // AutocompleteEditView depends on the browser instance.
+ // Create new one when the browser instance changes.
+ void Update(Browser* browser) {
+ // Detach the native view if any.
+ if (location_entry_view_ && location_entry_view_->native_view())
+ location_entry_view_->Detach();
+
+ location_entry_.reset(new AutocompleteEditViewGtk(
+ main_menu_, browser->toolbar_model(), browser->profile(),
+ browser->command_updater(), false, this));
+ location_entry_->Init();
+ gtk_widget_show_all(location_entry_->widget());
+ gtk_widget_hide(location_entry_->widget());
+
+ location_entry_view_->set_focus_view(this);
+ location_entry_view_->Attach(location_entry_->widget());
+ }
+
+ private:
+ MainMenu* main_menu_;
+ views::NativeViewHost* location_entry_view_;
+ scoped_ptr<AutocompleteEditViewGtk> location_entry_;
+
+ DISALLOW_COPY_AND_ASSIGN(NavigationBar);
+};
+
+// A container for the main menu's contents (navigation bar and renderer).
+class AppMenuContainer : public views::View {
+ public:
+ explicit AppMenuContainer(MainMenu* main_menu)
+ : View(),
+ main_menu_(main_menu) {
+ }
+
+ virtual ~AppMenuContainer() {
+ }
+
+ // views::View overrides.
+ virtual void Layout() {
+ if (GetChildViewCount() == 2 && !bounds().IsEmpty()) {
+ int render_width = width() - kBackgroundImageRight;
+ if (main_menu_->navigation_bar_->IsVisible()) {
+ main_menu_->navigation_bar_->SetBounds(
+ 0, kBackgroundImageTop, render_width, kNavigationBarHeight);
+ } else {
+ main_menu_->navigation_bar_->SetBounds(
+ gfx::Rect(0, kBackgroundImageTop, 0, 0));
+ }
+ int render_y = main_menu_->navigation_bar_->bounds().bottom();
+ int render_height =
+ std::max(0, height() - kBackgroundImageBottom - render_y);
+ gfx::Size rwhv_size = gfx::Size(render_width, render_height);
+
+ main_menu_->menu_content_view_->SetBounds(
+ 0, render_y, rwhv_size.width(), rwhv_size.height());
+ main_menu_->rwhv_->SetSize(rwhv_size);
+ }
+ }
+
+ virtual gfx::Size GetPreferredSize() {
+ // Not really used.
+ return gfx::Size();
+ }
+
+ // Hide if a mouse is clicked outside of the content area.
+ virtual bool OnMousePressed(const views::MouseEvent& event) {
+ if (HitTest(event.location()) &&
+ event.y() > main_menu_->navigation_bar_->y()) {
+ return false;
+ }
+ main_menu_->Hide();
+ return false;
+ }
+
+ private:
+ MainMenu* main_menu_;
+
+ DISALLOW_COPY_AND_ASSIGN(AppMenuContainer);
+};
+
// static
void MainMenu::Show(Browser* browser) {
MainMenu::Get()->ShowImpl(browser);
@@ -115,6 +253,10 @@ MainMenu::~MainMenu() {
// TODO(sky): fix this.
// menu_rvh_->Shutdown();
// popup_->CloseNow();
+ // if (location_entry_view_->native_view())
+ // location_entry_view_->Detach();
+ // etc
+ ActiveWindowWatcherX::RemoveObserver(this);
}
MainMenu::MainMenu()
@@ -125,19 +267,24 @@ MainMenu::MainMenu()
rwhv_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(tab_contents_delegate_(this)),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
+ menu_container_(NULL),
+ navigation_bar_(NULL),
+ menu_content_view_(NULL),
has_shown_(false) {
SkBitmap* drop_down_image = ResourceBundle::GetSharedInstance().
GetBitmapNamed(IDR_MAIN_MENU_BUTTON_DROP_DOWN);
-
views::WidgetGtk* menu_popup =
- new views::WidgetGtk(views::WidgetGtk::TYPE_POPUP);
+ new views::WidgetGtk(views::WidgetGtk::TYPE_WINDOW);
popup_ = menu_popup;
// The background image has transparency, so we make the window transparent.
menu_popup->MakeTransparent();
gfx::Size popup_size = GetPopupSize();
menu_popup->Init(NULL, gfx::Rect(0, 0, popup_size.width(),
popup_size.height()));
-
+ TabOverviewTypes::instance()->SetWindowType(
+ menu_popup->GetNativeView(),
+ TabOverviewTypes::WINDOW_TYPE_CHROME_INFO_BUBBLE,
+ NULL);
views::Painter* painter = views::Painter::CreateImagePainter(
*drop_down_image,
gfx::Insets(kBackgroundImageTop, kBackgroundImageLeft,
@@ -146,6 +293,12 @@ MainMenu::MainMenu()
menu_popup->GetRootView()->set_background(
views::Background::CreateBackgroundPainter(true, painter));
+ menu_container_ = new AppMenuContainer(this);
+ menu_popup->SetContentsView(menu_container_);
+
+ navigation_bar_ = new NavigationBar(this);
+ menu_container_->AddChildView(navigation_bar_);
+
GURL menu_url(GetMenuURL());
DCHECK(BrowserList::begin() != BrowserList::end());
// TODO(sky): this shouldn't pick a random profile to use.
@@ -159,12 +312,13 @@ MainMenu::MainMenu()
rwhv_ = new RenderWidgetHostViewGtk(menu_rvh_);
rwhv_->InitAsChild();
menu_rvh_->CreateRenderView(profile->GetRequestContext());
- menu_popup->AddChild(rwhv_->GetNativeView());
- gfx::Size rwhv_size = CalculateRWHVSize(popup_size);
- menu_popup->PositionChild(rwhv_->GetNativeView(), kRendererX, kRendererY,
- rwhv_size.width(), rwhv_size.height());
- rwhv_->SetSize(rwhv_size);
+
+ menu_content_view_ = new views::NativeViewHost;
+ menu_container_->AddChildView(menu_content_view_);
+ menu_content_view_->Attach(rwhv_->GetNativeView());
menu_rvh_->NavigateToURL(menu_url);
+
+ ActiveWindowWatcherX::AddObserver(this);
}
// static
@@ -175,36 +329,37 @@ MainMenu* MainMenu::Get() {
void MainMenu::ShowImpl(Browser* browser) {
Cleanup();
- browser_ = browser;
+ if (browser_ != browser) {
+ browser_ = browser;
+ navigation_bar_->Update(browser);
+ // Set the transient window so that ChromeOS WM treat this
+ // as if a popup window.
+ gtk_window_set_transient_for(
+ GTK_WINDOW(popup_->GetNativeView()),
+ GTK_WINDOW(browser_->window()->GetNativeHandle()));
+ }
+ BrowserView* bview = static_cast<BrowserView*>(browser->window());
+ navigation_bar_->SetVisible(bview->is_compact_style());
+ menu_container_->Layout();
popup_->Show();
GtkWidget* rwhv_widget = rwhv_->GetNativeView();
-
if (!has_shown_) {
has_shown_ = true;
gtk_widget_realize(rwhv_widget);
- 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. 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::ActiveWindowChanged(GdkWindow* active_window) {
+ if (!popup_->IsActive())
+ Hide();
+ else
+ navigation_bar_->RequestFocus();
}
void MainMenu::Hide() {
- gdk_keyboard_ungrab(GDK_CURRENT_TIME);
- gdk_pointer_ungrab(GDK_CURRENT_TIME);
-
popup_->Hide();
-
// The stack may have pending_contents_ on it. Delay deleting the
// pending_contents_ as TabContents doesn't deal well with being deleted
// while on the stack.
@@ -217,36 +372,13 @@ void MainMenu::Cleanup() {
method_factory_.RevokeAll();
}
-// 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 ||
- event->x >= widget->allocation.width ||
- event->y >= widget->allocation.height) {
- // The user clicked outside the bounds of the menu, delete the main which
- // results in closing it.
- Hide();
- }
- return FALSE;
-}
-
void MainMenu::RequestMove(const gfx::Rect& new_bounds) {
// Invoking PositionChild results in a gtk signal that triggers attempting to
// to resize the window. We need to set the size request so that it resizes
// correctly when this happens.
gtk_widget_set_size_request(popup_->GetNativeView(),
new_bounds.width(), new_bounds.height());
- gfx::Size rwhv_size = CalculateRWHVSize(new_bounds.size());
- popup_->PositionChild(rwhv_->GetNativeView(), kRendererX, kRendererY,
- rwhv_size.width(), rwhv_size.height());
popup_->SetBounds(new_bounds);
- rwhv_->SetSize(rwhv_size);
}
RendererPreferences MainMenu::GetRendererPrefs(Profile* profile) const {
@@ -255,6 +387,57 @@ RendererPreferences MainMenu::GetRendererPrefs(Profile* profile) const {
return preferences;
}
+// AutocompleteController implementation.
+void MainMenu::OnAutocompleteAccept(const GURL& url,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition,
+ const GURL& alternate_nav_url) {
+ AddTabWithURL(url, transition);
+ Hide();
+}
+
+void MainMenu::OnChanged() {
+}
+
+void MainMenu::OnInputInProgress(bool in_progress) {
+}
+
+void MainMenu::OnKillFocus() {
+}
+
+void MainMenu::OnSetFocus() {
+}
+
+SkBitmap MainMenu::GetFavIcon() const {
+ return SkBitmap();
+}
+
+std::wstring MainMenu::GetTitle() const {
+ return std::wstring();
+}
+
+void MainMenu::AddTabWithURL(const GURL& url,
+ PageTransition::Type transition) {
+ switch (StatusAreaView::GetOpenTabsMode()) {
+ case StatusAreaView::OPEN_TABS_ON_LEFT: {
+ // Add the new tab at the first non-pinned location.
+ int index = browser_->tabstrip_model()->IndexOfFirstNonMiniTab();
+ browser_->AddTabWithURL(url, GURL(), transition,
+ true, index, true, NULL);
+ break;
+ }
+ case StatusAreaView::OPEN_TABS_CLOBBER: {
+ browser_->GetSelectedTabContents()->controller().LoadURL(
+ url, GURL(), transition);
+ break;
+ }
+ case StatusAreaView::OPEN_TABS_ON_RIGHT: {
+ browser_->AddTabWithURL(url, GURL(), transition, true, -1, true, NULL);
+ break;
+ }
+ }
+}
+
void MainMenu::CreateNewWindow(int route_id) {
if (pending_contents_.get()) {
NOTREACHED();
diff --git a/chrome/browser/chromeos/main_menu.h b/chrome/browser/chromeos/main_menu.h
index 359c120..5cc567b 100644
--- a/chrome/browser/chromeos/main_menu.h
+++ b/chrome/browser/chromeos/main_menu.h
@@ -7,14 +7,17 @@
#include <gtk/gtk.h>
+#include "app/active_window_watcher_x.h"
#include "base/scoped_ptr.h"
#include "base/singleton.h"
#include "base/task.h"
+#include "chrome/browser/autocomplete/autocomplete_edit.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
#include "chrome/common/renderer_preferences.h"
+class AutocompleteEditViewGtk;
class Browser;
class RenderWidgetHostViewGtk;
class SiteInstance;
@@ -23,14 +26,22 @@ namespace gfx {
class Size;
}
namespace views {
+class NativeViewHost;
+class View;
class WidgetGtk;
}
namespace chromeos {
-// MainMenu manages showing the main menu. The menu is currently an HTML page.
-// When the user clicks a link on the page a new tab is added to the current
-// browser and the menu is hidden.
+class NavigationBar;
+
+// MainMenu manages showing the main menu and optionally the
+// navigation bar in compact navigation bar mode. The menu is
+// currently an HTML page. When the user clicks a link on the page a
+// new tab is added to the current browser and the menu is hidden.
+// When the user opens a new page from the navigation bar, it opens a
+// new tab on left, on right or clobbers the current tab depending on
+// the configuration.
//
// To show the menu invoke Show.
//
@@ -51,7 +62,9 @@ namespace chromeos {
// the life of the browser. This is done to make sure we have the html page
// loaded when the user clicks on it.
class MainMenu : public RenderViewHostDelegate,
- public RenderViewHostDelegate::View {
+ public RenderViewHostDelegate::View,
+ public AutocompleteEditController,
+ public ActiveWindowWatcherX::Observer {
public:
// Shows the menu.
static void Show(Browser* browser);
@@ -110,6 +123,7 @@ class MainMenu : public RenderViewHostDelegate,
};
friend class TabContentsDelegateImpl;
+ friend class AppMenuContainer;
MainMenu();
@@ -126,14 +140,6 @@ class MainMenu : public RenderViewHostDelegate,
// hidden.
void Cleanup();
- // Callback from button presses on the render widget host view. Clicks
- // outside the widget resulting in closing the menu.
- static gboolean CallButtonPressEvent(GtkWidget* widget,
- GdkEventButton* event,
- MainMenu* menu);
- gboolean OnButtonPressEvent(GtkWidget* widget,
- GdkEventButton* event);
-
// RenderViewHostDelegate overrides.
virtual int GetBrowserWindowID() const {
return -1;
@@ -171,6 +177,23 @@ class MainMenu : public RenderViewHostDelegate,
virtual void HandleMouseLeave() {}
virtual void UpdatePreferredSize(const gfx::Size& pref_size) {}
+ // AutocompleteController implementation.
+ virtual void OnAutocompleteAccept(const GURL& url,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition,
+ const GURL& alternate_nav_url);
+ virtual void OnChanged();
+ virtual void OnInputInProgress(bool in_progress);
+ virtual void OnKillFocus();
+ virtual void OnSetFocus();
+ virtual SkBitmap GetFavIcon() const;
+ virtual std::wstring GetTitle() const;
+
+ // ActiveWindowWatcherX::Observer implementation.
+ virtual void ActiveWindowChanged(GdkWindow* active_window);
+
+ void AddTabWithURL(const GURL& url, PageTransition::Type transition);
+
// The currently active browser. We use this to open urls.
Browser* browser_;
@@ -197,6 +220,15 @@ class MainMenu : public RenderViewHostDelegate,
ScopedRunnableMethodFactory<MainMenu> method_factory_;
+ // Container of NavigationBar and Renderer.
+ views::View* menu_container_;
+
+ // The navigation bar. Only shown in compact navigation bar mode.
+ NavigationBar* navigation_bar_;
+
+ // The Renderer view.
+ views::NativeViewHost* menu_content_view_;
+
// True if the popup has ever been shown.
bool has_shown_;