diff options
author | avayvod@chromium.org <avayvod@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-02 18:55:36 +0000 |
---|---|---|
committer | avayvod@chromium.org <avayvod@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-02 18:55:36 +0000 |
commit | 527bb7f151b5f44c5274f9d27b13ee3b32ef9bf4 (patch) | |
tree | dadd3342a4240c2960bdd7160b4dde05d897b67c | |
parent | 0bbec1fd7a1db9865dc10902840272c5213e0daf (diff) | |
download | chromium_src-527bb7f151b5f44c5274f9d27b13ee3b32ef9bf4.zip chromium_src-527bb7f151b5f44c5274f9d27b13ee3b32ef9bf4.tar.gz chromium_src-527bb7f151b5f44c5274f9d27b13ee3b32ef9bf4.tar.bz2 |
Made StatusAreaView and its buttons independent of BrowserWindow.
StatusAreaHost interface introduced so its other implementation can be used
for login wizard status area.
BUG=33197
TEST=No regression should be visible when logged in.
Review URL: http://codereview.chromium.org/552215
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37854 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-x | chrome/browser/chromeos/browser_status_area_view.cc | 164 | ||||
-rw-r--r-- | chrome/browser/chromeos/browser_status_area_view.h | 64 | ||||
-rw-r--r-- | chrome/browser/chromeos/chromeos_browser_view.cc | 26 | ||||
-rw-r--r-- | chrome/browser/chromeos/chromeos_browser_view.h | 19 | ||||
-rw-r--r-- | chrome/browser/chromeos/clock_menu_button.cc | 26 | ||||
-rw-r--r-- | chrome/browser/chromeos/clock_menu_button.h | 30 | ||||
-rw-r--r-- | chrome/browser/chromeos/language_menu_button.cc | 23 | ||||
-rw-r--r-- | chrome/browser/chromeos/language_menu_button.h | 14 | ||||
-rw-r--r-- | chrome/browser/chromeos/status_area_host.h | 36 | ||||
-rwxr-xr-x | chrome/browser/chromeos/status_area_view.cc | 172 | ||||
-rw-r--r-- | chrome/browser/chromeos/status_area_view.h | 41 | ||||
-rwxr-xr-x | chrome/chrome_browser.gypi | 3 |
12 files changed, 356 insertions, 262 deletions
diff --git a/chrome/browser/chromeos/browser_status_area_view.cc b/chrome/browser/chromeos/browser_status_area_view.cc new file mode 100755 index 0000000..df37da2 --- /dev/null +++ b/chrome/browser/chromeos/browser_status_area_view.cc @@ -0,0 +1,164 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/browser_status_area_view.h" + +#include "app/l10n_util.h" +#include "app/theme_provider.h" +#include "base/string_util.h" +#include "chrome/app/chrome_dll_resource.h" +#include "chrome/browser/app_menu_model.h" +#include "chrome/browser/browser.h" +#include "chrome/browser/browser_window.h" +#include "chrome/browser/browser_theme_provider.h" +#include "chrome/browser/chromeos/chromeos_browser_view.h" +#include "chrome/browser/chromeos/status_area_button.h" +#include "chrome/browser/chromeos/status_area_view.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/views/theme_background.h" +#include "chrome/browser/views/toolbar_view.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/pref_service.h" +#include "grit/chromium_strings.h" +#include "grit/generated_resources.h" +#include "grit/theme_resources.h" +#include "views/controls/menu/menu.h" +#include "views/controls/menu/menu_2.h" +#include "views/window/window.h" + +namespace chromeos { + +class OptionsMenuModel : public menus::SimpleMenuModel, + public menus::SimpleMenuModel::Delegate { + public: + // These extra command IDs must be unique when combined with the options, + // so we just pick up the numbering where that stops. + enum OtherCommands { + CREATE_NEW_WINDOW = StatusAreaView::OPEN_TABS_ON_RIGHT + 1, + }; + + explicit OptionsMenuModel(Browser* browser) + : SimpleMenuModel(this), + browser_(browser) { + AddItemWithStringId(IDC_COMPACT_NAVBAR, IDS_COMPACT_NAVBAR); + AddSeparator(); + + AddItem(static_cast<int>(StatusAreaView::OPEN_TABS_ON_LEFT), + ASCIIToUTF16("Open tabs on left")); + AddItem(static_cast<int>(StatusAreaView::OPEN_TABS_CLOBBER), + ASCIIToUTF16("Open tabs clobber")); + AddItem(static_cast<int>(StatusAreaView::OPEN_TABS_ON_RIGHT), + ASCIIToUTF16("Open tabs on right")); + } + virtual ~OptionsMenuModel() { + } + + // SimpleMenuModel::Delegate implementation. + virtual bool IsCommandIdChecked(int command_id) const { + return StatusAreaView::GetOpenTabsMode() == command_id; + } + virtual bool IsCommandIdEnabled(int command_id) const { + return true; + } + virtual bool GetAcceleratorForCommandId( + int command_id, + menus::Accelerator* accelerator) { + return false; + } + virtual void ExecuteCommand(int command_id) { + switch (command_id) { + case IDC_COMPACT_NAVBAR: + browser_->ExecuteCommand(command_id); + break; + case StatusAreaView::OPEN_TABS_ON_LEFT: + case StatusAreaView::OPEN_TABS_CLOBBER: + case StatusAreaView::OPEN_TABS_ON_RIGHT: + StatusAreaView::SetOpenTabsMode( + static_cast<StatusAreaView::OpenTabsMode>(command_id)); + break; + default: + NOTREACHED(); + } + } + + private: + Browser* browser_; + + DISALLOW_COPY_AND_ASSIGN(OptionsMenuModel); +}; + +BrowserStatusAreaView::BrowserStatusAreaView(ChromeosBrowserView* browser_view) + : StatusAreaView(browser_view), + browser_view_(browser_view), + menu_view_(NULL) { +} + +void BrowserStatusAreaView::Init() { + StatusAreaView::Init(); + ThemeProvider* theme = browser_view_->frame()->GetThemeProviderForFrame(); + +// Menu. + menu_view_ = new StatusAreaButton(this); + menu_view_->SetIcon(*theme->GetBitmapNamed(IDR_STATUSBAR_MENU)); + AddChildView(menu_view_); + + set_background(new ThemeBackground(browser_view_)); + + app_menu_contents_.reset(CreateAppMenuModel(this)); + app_menu_menu_.reset(new views::Menu2(app_menu_contents_.get())); +} + +AppMenuModel* BrowserStatusAreaView::CreateAppMenuModel( + menus::SimpleMenuModel::Delegate* delegate) { + Browser* browser = browser_view_->browser(); + AppMenuModel* menu_model = new AppMenuModel(delegate, browser); + + // Options menu always uses StatusAreaView as delegate, so + // we can reuse it. + if (!options_menu_contents_.get()) + options_menu_contents_.reset(new OptionsMenuModel(browser)); + + int sync_index = menu_model->GetIndexOfCommandId(IDC_SYNC_BOOKMARKS); + DCHECK_GE(sync_index, 0); + menu_model->InsertItemWithStringIdAt( + sync_index + 1, IDC_CLEAR_BROWSING_DATA, IDS_CLEAR_BROWSING_DATA); + menu_model->InsertSeparatorAt(sync_index + 1); + + int options_index = menu_model->GetIndexOfCommandId(IDC_OPTIONS); + DCHECK_GE(options_index, 0); + menu_model->InsertSubMenuAt( + options_index + 1, + ASCIIToUTF16("Compact nav bar"), options_menu_contents_.get()); + return menu_model; +} + +bool BrowserStatusAreaView::IsCommandIdChecked(int command_id) const { + if (command_id == IDC_SHOW_BOOKMARK_BAR) + return browser_view_->browser()->profile()->GetPrefs()->GetBoolean( + prefs::kShowBookmarkBar); + return false; +} + +bool BrowserStatusAreaView::IsCommandIdEnabled(int command_id) const { + Browser* browser = browser_view_->browser(); + if (command_id == IDC_RESTORE_TAB) + return browser->CanRestoreTab(); + return browser->command_updater()->IsCommandEnabled(command_id); +} + +bool BrowserStatusAreaView::GetAcceleratorForCommandId( + int command_id, + menus::Accelerator* accelerator) { + return false; +} + +void BrowserStatusAreaView::ExecuteCommand(int command_id) { + browser_view_->browser()->ExecuteCommand(command_id); +} + +void BrowserStatusAreaView::RunMenu(views::View* source, const gfx::Point& pt) { + app_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); +} + +} // namespace chromeos diff --git a/chrome/browser/chromeos/browser_status_area_view.h b/chrome/browser/chromeos/browser_status_area_view.h new file mode 100644 index 0000000..8220abe --- /dev/null +++ b/chrome/browser/chromeos/browser_status_area_view.h @@ -0,0 +1,64 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_BROWSER_STATUS_AREA_VIEW_H_ +#define CHROME_BROWSER_CHROMEOS_BROWSER_STATUS_AREA_VIEW_H_ + +#include "app/menus/simple_menu_model.h" +#include "base/basictypes.h" +#include "chrome/browser/chromeos/status_area_view.h" +#include "views/controls/menu/view_menu_delegate.h" +#include "views/controls/menu/menu_2.h" +#include "views/view.h" + +class AppMenuModel; + +namespace chromeos { + +class ChromeosBrowserView; +class StatusAreaButton; + +// StatusAreView specialization specific for Chrome browser. +// Adds a menu button visible in compact location bar mode. +class BrowserStatusAreaView : public StatusAreaView, + public menus::SimpleMenuModel::Delegate, + public views::ViewMenuDelegate { + public: + explicit BrowserStatusAreaView(ChromeosBrowserView* browser_view); + virtual ~BrowserStatusAreaView() {} + + virtual void Init(); + + // Creates an AppMenuModel for chromeos. + AppMenuModel* CreateAppMenuModel(menus::SimpleMenuModel::Delegate* delegate); + + StatusAreaButton* menu_view() const { return menu_view_; } + + private: + + // menus::SimpleMenuModel::Delegate implementation. + virtual bool IsCommandIdChecked(int command_id) const; + virtual bool IsCommandIdEnabled(int command_id) const; + virtual bool GetAcceleratorForCommandId(int command_id, + menus::Accelerator* accelerator); + virtual void ExecuteCommand(int command_id); + + // views::ViewMenuDelegate implementation. + virtual void RunMenu(views::View* source, const gfx::Point& pt); + + // The browser window that owns us. + ChromeosBrowserView* browser_view_; + + StatusAreaButton* menu_view_; + + scoped_ptr<menus::SimpleMenuModel> app_menu_contents_; + scoped_ptr<menus::SimpleMenuModel> options_menu_contents_; + scoped_ptr<views::Menu2> app_menu_menu_; + + DISALLOW_COPY_AND_ASSIGN(BrowserStatusAreaView); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_BROWSER_STATUS_AREA_VIEW_H_ diff --git a/chrome/browser/chromeos/chromeos_browser_view.cc b/chrome/browser/chromeos/chromeos_browser_view.cc index 4ebf8dd..057ada4 100644 --- a/chrome/browser/chromeos/chromeos_browser_view.cc +++ b/chrome/browser/chromeos/chromeos_browser_view.cc @@ -4,16 +4,20 @@ #include "chrome/browser/chromeos/chromeos_browser_view.h" +#include <algorithm> +#include <string> + #include "app/gfx/canvas.h" #include "app/menus/simple_menu_model.h" #include "app/theme_provider.h" #include "base/command_line.h" #include "chrome/app/chrome_dll_resource.h" +#include "chrome/browser/chromeos/browser_status_area_view.h" #include "chrome/browser/chromeos/compact_location_bar_host.h" #include "chrome/browser/chromeos/compact_navigation_bar.h" #include "chrome/browser/chromeos/main_menu.h" #include "chrome/browser/chromeos/panel_browser_view.h" -#include "chrome/browser/chromeos/status_area_view.h" +#include "chrome/browser/chromeos/status_area_button.h" #include "chrome/browser/view_ids.h" #include "chrome/browser/views/frame/browser_extender.h" #include "chrome/browser/views/frame/browser_frame_gtk.h" @@ -324,6 +328,9 @@ ChromeosBrowserView::ChromeosBrowserView(Browser* browser) force_maximized_window_(false) { } +ChromeosBrowserView::~ChromeosBrowserView() { +} + //////////////////////////////////////////////////////////////////////////////// // ChromeosBrowserView, ChromeBrowserView overrides: @@ -346,7 +353,7 @@ void ChromeosBrowserView::Init() { compact_navigation_bar_->SetID(VIEW_ID_COMPACT_NAV_BAR); AddChildView(compact_navigation_bar_); compact_navigation_bar_->Init(); - status_area_ = new chromeos::StatusAreaView(this); + status_area_ = new BrowserStatusAreaView(this); status_area_->SetID(VIEW_ID_STATUS_AREA); AddChildView(status_area_); status_area_->Init(); @@ -436,6 +443,21 @@ void ChromeosBrowserView::ShowContextMenu(views::View* source, system_menu_menu_->RunMenuAt(gfx::Point(x, y), views::Menu2::ALIGN_TOPLEFT); } +// StatusAreaHost overrides. +gfx::NativeWindow ChromeosBrowserView::GetNativeWindow() const { + return GetWindow()->GetNativeWindow(); +} + +void ChromeosBrowserView::OpenSystemOptionsDialog() const { + browser()->OpenSystemOptionsDialog(); +} + +bool ChromeosBrowserView::IsButtonVisible(views::View* button_view) const { + if (button_view == status_area_->menu_view()) + return !IsToolbarVisible(); + return true; +} + //////////////////////////////////////////////////////////////////////////////// // ChromeosBrowserView public: diff --git a/chrome/browser/chromeos/chromeos_browser_view.h b/chrome/browser/chromeos/chromeos_browser_view.h index b7a127e..2000674 100644 --- a/chrome/browser/chromeos/chromeos_browser_view.h +++ b/chrome/browser/chromeos/chromeos_browser_view.h @@ -5,6 +5,7 @@ #ifndef CHROME_BROWSER_CHROMEOS_CHROMEOS_BROWSER_VIEW_H_ #define CHROME_BROWSER_CHROMEOS_CHROMEOS_BROWSER_VIEW_H_ +#include "chrome/browser/chromeos/status_area_host.h" #include "chrome/browser/views/frame/browser_view.h" class TabStripModel; @@ -20,10 +21,11 @@ class Menu2; namespace chromeos { +class BrowserStatusAreaView; class CompactLocationBar; class CompactLocationBarHost; class CompactNavigationBar; -class StatusAreaView; +class StatusAreaButton; // ChromeosBrowserView adds ChromeOS specific controls and menus to a // BrowserView created with Browser::TYPE_NORMAL. This extender adds @@ -34,7 +36,8 @@ class StatusAreaView; // and adds the system context menu to the remaining arae of the titlebar. class ChromeosBrowserView : public BrowserView, public views::ButtonListener, - public views::ContextMenuController { + public views::ContextMenuController, + public StatusAreaHost { public: // There are 3 ui styles, standard, compact and sidebar. // Standard uses the same layout as chromium/chrome browser. @@ -49,7 +52,7 @@ class ChromeosBrowserView : public BrowserView, }; explicit ChromeosBrowserView(Browser* browser); - virtual ~ChromeosBrowserView() {} + virtual ~ChromeosBrowserView(); // BrowserView overrides. virtual void Init(); @@ -69,6 +72,11 @@ class ChromeosBrowserView : public BrowserView, int y, bool is_mouse_gesture); + // StatusAreaHost overrides. + virtual gfx::NativeWindow GetNativeWindow() const; + virtual void OpenSystemOptionsDialog() const; + virtual bool IsButtonVisible(views::View* button_view) const; + // Shows the compact location bar under the selected tab. void ShowCompactLocationBarUnderSelectedTab(); @@ -89,7 +97,7 @@ class ChromeosBrowserView : public BrowserView, views::ImageButton* main_menu_; // Status Area view. - chromeos::StatusAreaView* status_area_; + BrowserStatusAreaView* status_area_; // System menus. scoped_ptr<menus::SimpleMenuModel> system_menu_contents_; @@ -111,6 +119,9 @@ class ChromeosBrowserView : public BrowserView, // is active. views::View* spacer_; + // Menu button shown in status area when browser is in compact mode. + StatusAreaButton* menu_view_; + DISALLOW_COPY_AND_ASSIGN(ChromeosBrowserView); }; diff --git a/chrome/browser/chromeos/clock_menu_button.cc b/chrome/browser/chromeos/clock_menu_button.cc index 745fe24..eecff67 100644 --- a/chrome/browser/chromeos/clock_menu_button.cc +++ b/chrome/browser/chromeos/clock_menu_button.cc @@ -12,9 +12,8 @@ #include "base/string_util.h" #include "base/time.h" #include "chrome/browser/browser.h" +#include "chrome/browser/chromeos/status_area_host.h" #include "chrome/browser/profile.h" -#include "chrome/common/notification_service.h" -#include "chrome/common/pref_names.h" #include "grit/generated_resources.h" #include "unicode/calendar.h" @@ -24,9 +23,9 @@ namespace chromeos { // when the timer goes off. const int kTimerSlopSeconds = 1; -ClockMenuButton::ClockMenuButton(Browser* browser) +ClockMenuButton::ClockMenuButton(StatusAreaHost* host) : MenuButton(NULL, std::wstring(), this, false), - browser_(browser) { + host_(host) { set_border(NULL); SetFont(ResourceBundle::GetSharedInstance().GetFont( ResourceBundle::BaseFont).DeriveFont(0, gfx::Font::BOLD)); @@ -38,20 +37,6 @@ ClockMenuButton::ClockMenuButton(Browser* browser) SetText(l10n_util::GetStringF(IDS_STATUSBAR_CLOCK_SHORT_TIME_PM, zero, zero)); set_alignment(TextButton::ALIGN_RIGHT); UpdateTextAndSetNextTimer(); - if (browser_ != NULL) { - // Init member prefs so we can update the controls if prefs change. - timezone_.Init(prefs::kTimeZone, browser_->profile()->GetPrefs(), this); - } -} - -void ClockMenuButton::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - if (type == NotificationType::PREF_CHANGED) { - const std::wstring* pref_name = Details<std::wstring>(details).ptr(); - if (!pref_name || *pref_name == prefs::kTimeZone) - UpdateText(); - } } void ClockMenuButton::UpdateTextAndSetNextTimer() { @@ -110,7 +95,7 @@ void ClockMenuButton::UpdateText() { // ClockMenuButton, menus::MenuModel implementation: int ClockMenuButton::GetItemCount() const { - return browser_ == NULL ? 1 : 3; + return 3; } menus::MenuModel::ItemType ClockMenuButton::GetTypeAt(int index) const { @@ -132,8 +117,7 @@ bool ClockMenuButton::IsEnabledAt(int index) const { } void ClockMenuButton::ActivatedAt(int index) { - if (browser_ != NULL) - browser_->OpenSystemOptionsDialog(); + host_->OpenSystemOptionsDialog(); } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/chromeos/clock_menu_button.h b/chrome/browser/chromeos/clock_menu_button.h index b3d0543..09d3e9d 100644 --- a/chrome/browser/chromeos/clock_menu_button.h +++ b/chrome/browser/chromeos/clock_menu_button.h @@ -7,27 +7,21 @@ #include "base/scoped_ptr.h" #include "base/timer.h" -#include "chrome/common/notification_observer.h" -#include "chrome/common/pref_member.h" #include "views/controls/button/menu_button.h" #include "views/controls/menu/menu_2.h" #include "views/controls/menu/view_menu_delegate.h" -class Browser; - namespace chromeos { +class StatusAreaHost; + // The clock menu button in the status area. // This button shows the current time. class ClockMenuButton : public views::MenuButton, public views::ViewMenuDelegate, - public menus::MenuModel, - public NotificationObserver { + public menus::MenuModel { public: - // Browser can be NULL in case we're showing the button from login - // manager. In this case timezone is initialized to PST and options dialog - // menu is absent. - explicit ClockMenuButton(Browser* browser); + explicit ClockMenuButton(StatusAreaHost* host); virtual ~ClockMenuButton() {} // menus::MenuModel implementation. @@ -48,10 +42,9 @@ class ClockMenuButton : public views::MenuButton, virtual void ActivatedAt(int index); virtual void MenuWillShow() {} - // Overridden from NotificationObserver: - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); + // Updates the time on the menu button. Can be called by host if timezone + // changes. + void UpdateText(); private: // views::ViewMenuDelegate implementation. @@ -60,21 +53,14 @@ class ClockMenuButton : public views::MenuButton, // Updates text and schedules the timer to fire at the next minute interval. void UpdateTextAndSetNextTimer(); - // Updates the time on the menu button. - void UpdateText(); - base::OneShotTimer<ClockMenuButton> timer_; - StringPrefMember timezone_; - // The clock menu. // NOTE: we use a scoped_ptr here as menu calls into 'this' from the // constructor. scoped_ptr<views::Menu2> clock_menu_; - // The browser object. Can be NULL if the button is on the login manager - // screen. - Browser* browser_; + StatusAreaHost* host_; DISALLOW_COPY_AND_ASSIGN(ClockMenuButton); }; diff --git a/chrome/browser/chromeos/language_menu_button.cc b/chrome/browser/chromeos/language_menu_button.cc index 9804bcd..54cc7ff 100644 --- a/chrome/browser/chromeos/language_menu_button.cc +++ b/chrome/browser/chromeos/language_menu_button.cc @@ -9,7 +9,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/time.h" -#include "chrome/browser/browser.h" +#include "chrome/browser/chromeos/status_area_host.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -103,7 +103,7 @@ namespace chromeos { //////////////////////////////////////////////////////////////////////////////// // LanguageMenuButton -LanguageMenuButton::LanguageMenuButton(Browser* browser) +LanguageMenuButton::LanguageMenuButton(StatusAreaHost* host) : MenuButton(NULL, std::wstring(), this, false), language_list_(LanguageLibrary::Get()->GetActiveLanguages()), model_(NULL), @@ -111,7 +111,7 @@ LanguageMenuButton::LanguageMenuButton(Browser* browser) // in this class. Therefore, GetItemCount() have to return 0 when // |model_| is NULL. ALLOW_THIS_IN_INITIALIZER_LIST(language_menu_(this)), - browser_(browser) { + host_(host) { DCHECK(language_list_.get() && !language_list_->empty()); // Update the model RebuildModel(); @@ -266,8 +266,8 @@ void LanguageMenuButton::ActivatedAt(int index) { DCHECK_GE(index, 0); DCHECK(language_list_.get()); - if (browser_ != NULL && IndexPointsToConfigureImeMenuItem(index)) { - browser_->OpenSystemOptionsDialog(); + if (IndexPointsToConfigureImeMenuItem(index)) { + host_->OpenSystemOptionsDialog(); return; } @@ -369,14 +369,11 @@ void LanguageMenuButton::RebuildModel() { need_separator = true; } - // Can't configure IME if on login screen. - if (browser_ != NULL) { - // Note: We use AddSeparator() for separators, and AddRadioItem() for all - // other items even if an item is not actually a radio item. - if (need_separator) - model_->AddSeparator(); - model_->AddRadioItem(COMMAND_ID_CONFIGURE_IME, dummy_label, 0 /* dummy */); - } + // Note: We use AddSeparator() for separators, and AddRadioItem() for all + // other items even if an item is not actually a radio item. + if (need_separator) + model_->AddSeparator(); + model_->AddRadioItem(COMMAND_ID_CONFIGURE_IME, dummy_label, 0 /* dummy */); } bool LanguageMenuButton::IndexIsInLanguageList(int index) const { diff --git a/chrome/browser/chromeos/language_menu_button.h b/chrome/browser/chromeos/language_menu_button.h index 4cab71d..fd5285e 100644 --- a/chrome/browser/chromeos/language_menu_button.h +++ b/chrome/browser/chromeos/language_menu_button.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,11 +11,12 @@ #include "views/controls/menu/menu_2.h" #include "views/controls/menu/view_menu_delegate.h" -class Browser; class SkBitmap; namespace chromeos { +class StatusAreaHost; + // The language menu button in the status area. // This class will handle getting the IME/XKB status and populating the menu. class LanguageMenuButton : public views::MenuButton, @@ -23,10 +24,7 @@ class LanguageMenuButton : public views::MenuButton, public menus::MenuModel, public LanguageLibrary::Observer { public: - // If |browser| is null, options are unavailable and corresponding menu - // item is not shown. This happens when the button is shown on login - // screen and browser is not loaded yet. - explicit LanguageMenuButton(Browser* browser); + explicit LanguageMenuButton(StatusAreaHost* host); virtual ~LanguageMenuButton(); // menus::MenuModel implementation. @@ -85,8 +83,8 @@ class LanguageMenuButton : public views::MenuButton, // The language menu which pops up when the button in status area is clicked. views::Menu2 language_menu_; - // The browser object. May be null if the button is on login screen. - Browser* browser_; + + StatusAreaHost* host_; DISALLOW_COPY_AND_ASSIGN(LanguageMenuButton); }; diff --git a/chrome/browser/chromeos/status_area_host.h b/chrome/browser/chromeos/status_area_host.h new file mode 100644 index 0000000..f8af405 --- /dev/null +++ b/chrome/browser/chromeos/status_area_host.h @@ -0,0 +1,36 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_STATUS_AREA_HOST_H_ +#define CHROME_BROWSER_CHROMEOS_STATUS_AREA_HOST_H_ + +#include "app/gfx/native_widget_types.h" + +namespace views { +class View; +} // namespace views + +namespace chromeos { + +// This class is an abstraction decoupling StatusAreaView from its host +// window. +class StatusAreaHost { + public: + // Returns native window hosting the status area. + virtual gfx::NativeWindow GetNativeWindow() const = 0; + + // Opens system options dialog. + virtual void OpenSystemOptionsDialog() const = 0; + + // Indicates if the button specified should be visible at the moment. + virtual bool IsButtonVisible(views::View* button_view) const = 0; + + protected: + virtual ~StatusAreaHost() {} +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_STATUS_AREA_HOST_H_ + diff --git a/chrome/browser/chromeos/status_area_view.cc b/chrome/browser/chromeos/status_area_view.cc index a957c7a..1430156 100755 --- a/chrome/browser/chromeos/status_area_view.cc +++ b/chrome/browser/chromeos/status_area_view.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,31 +7,11 @@ #include <algorithm> #include "app/gfx/canvas.h" -#include "app/l10n_util.h" -#include "app/theme_provider.h" -#include "base/string_util.h" -#include "chrome/app/chrome_dll_resource.h" -#include "chrome/browser/app_menu_model.h" -#include "chrome/browser/browser.h" -#include "chrome/browser/browser_window.h" -#include "chrome/browser/browser_theme_provider.h" #include "chrome/browser/chromeos/clock_menu_button.h" #include "chrome/browser/chromeos/language_menu_button.h" #include "chrome/browser/chromeos/network_menu_button.h" #include "chrome/browser/chromeos/power_menu_button.h" -#include "chrome/browser/chromeos/status_area_button.h" -#include "chrome/browser/profile.h" -#include "chrome/browser/views/frame/browser_view.h" -#include "chrome/browser/views/theme_background.h" -#include "chrome/browser/views/toolbar_view.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/pref_service.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "grit/theme_resources.h" -#include "views/controls/menu/menu.h" -#include "views/controls/menu/menu_2.h" -#include "views/window/window.h" +#include "chrome/browser/chromeos/status_area_host.h" namespace chromeos { @@ -46,112 +26,42 @@ const int kLanguageSeparation = 4; // BrowserWindowGtk tiles its image with this offset const int kCustomFrameBackgroundVerticalOffset = 15; -class OptionsMenuModel : public menus::SimpleMenuModel, - public menus::SimpleMenuModel::Delegate { - public: - // These extra command IDs must be unique when combined with the options, - // so we just pick up the numbering where that stops. - enum OtherCommands { - CREATE_NEW_WINDOW = StatusAreaView::OPEN_TABS_ON_RIGHT + 1, - }; - - explicit OptionsMenuModel(Browser* browser) - : SimpleMenuModel(this), - browser_(browser) { - AddItemWithStringId(IDC_COMPACT_NAVBAR, IDS_COMPACT_NAVBAR); - AddSeparator(); - - AddItem(static_cast<int>(StatusAreaView::OPEN_TABS_ON_LEFT), - ASCIIToUTF16("Open tabs on left")); - AddItem(static_cast<int>(StatusAreaView::OPEN_TABS_CLOBBER), - ASCIIToUTF16("Open tabs clobber")); - AddItem(static_cast<int>(StatusAreaView::OPEN_TABS_ON_RIGHT), - ASCIIToUTF16("Open tabs on right")); - } - virtual ~OptionsMenuModel() { - } - - // SimpleMenuModel::Delegate implementation. - virtual bool IsCommandIdChecked(int command_id) const { - return StatusAreaView::GetOpenTabsMode() == command_id; - } - virtual bool IsCommandIdEnabled(int command_id) const { - return true; - } - virtual bool GetAcceleratorForCommandId( - int command_id, - menus::Accelerator* accelerator) { - return false; - } - virtual void ExecuteCommand(int command_id) { - switch (command_id) { - case IDC_COMPACT_NAVBAR: - browser_->ExecuteCommand(command_id); - break; - case StatusAreaView::OPEN_TABS_ON_LEFT: - case StatusAreaView::OPEN_TABS_CLOBBER: - case StatusAreaView::OPEN_TABS_ON_RIGHT: - StatusAreaView::SetOpenTabsMode( - static_cast<StatusAreaView::OpenTabsMode>(command_id)); - break; - default: - NOTREACHED(); - } - } - - private: - Browser* browser_; - - DISALLOW_COPY_AND_ASSIGN(OptionsMenuModel); -}; - // Default to opening new tabs on the left. StatusAreaView::OpenTabsMode StatusAreaView::open_tabs_mode_ = StatusAreaView::OPEN_TABS_ON_LEFT; -StatusAreaView::StatusAreaView(BrowserView* browser_view) - : browser_view_(browser_view), +StatusAreaView::StatusAreaView(StatusAreaHost* host) + : host_(host), clock_view_(NULL), language_view_(NULL), network_view_(NULL), - battery_view_(NULL), - menu_view_(NULL) { + power_view_(NULL) { } void StatusAreaView::Init() { - ThemeProvider* theme = browser_view_->frame()->GetThemeProviderForFrame(); - Browser* browser = browser_view_->browser(); // Language. - language_view_ = new LanguageMenuButton(browser); + language_view_ = new LanguageMenuButton(host_); AddChildView(language_view_); // Clock. - clock_view_ = new ClockMenuButton(browser); + clock_view_ = new ClockMenuButton(host_); AddChildView(clock_view_); - // Battery. - battery_view_ = new PowerMenuButton(); - AddChildView(battery_view_); + // Power. + power_view_ = new PowerMenuButton(); + AddChildView(power_view_); // Network. network_view_ = new NetworkMenuButton( - browser_view_->GetWindow()->GetNativeWindow()); - + host_->GetNativeWindow()); AddChildView(network_view_); - - // Menu. - menu_view_ = new StatusAreaButton(this); - menu_view_->SetIcon(*theme->GetBitmapNamed(IDR_STATUSBAR_MENU)); - AddChildView(menu_view_); - - set_background(new ThemeBackground(browser_view_)); - - app_menu_contents_.reset(CreateAppMenuModel(this)); - app_menu_menu_.reset(new views::Menu2(app_menu_contents_.get())); } void StatusAreaView::Update() { - menu_view_->SetVisible(!browser_view_->IsToolbarVisible()); + for (int i = 0; i < GetChildViewCount(); ++i) { + views::View* cur = GetChildViewAt(i); + cur->SetVisible(host_->IsButtonVisible(cur)); + } } gfx::Size StatusAreaView::GetPreferredSize() { @@ -206,56 +116,4 @@ void StatusAreaView::SetOpenTabsMode(OpenTabsMode mode) { open_tabs_mode_ = mode; } -AppMenuModel* StatusAreaView::CreateAppMenuModel( - menus::SimpleMenuModel::Delegate* delegate) { - Browser* browser = browser_view_->browser(); - AppMenuModel* menu_model = new AppMenuModel(delegate, browser); - - // Options menu always uses StatusAreaView as delegate, so - // we can reuse it. - if (!options_menu_contents_.get()) - options_menu_contents_.reset(new OptionsMenuModel(browser)); - - int sync_index = menu_model->GetIndexOfCommandId(IDC_SYNC_BOOKMARKS); - DCHECK_GE(sync_index, 0); - menu_model->InsertItemWithStringIdAt( - sync_index + 1, IDC_CLEAR_BROWSING_DATA, IDS_CLEAR_BROWSING_DATA); - menu_model->InsertSeparatorAt(sync_index + 1); - - int options_index = menu_model->GetIndexOfCommandId(IDC_OPTIONS); - DCHECK_GE(options_index, 0); - menu_model->InsertSubMenuAt( - options_index + 1, - ASCIIToUTF16("Compact nav bar"), options_menu_contents_.get()); - return menu_model; -} - -bool StatusAreaView::IsCommandIdChecked(int command_id) const { - if (command_id == IDC_SHOW_BOOKMARK_BAR) - return browser_view_->browser()->profile()->GetPrefs()->GetBoolean( - prefs::kShowBookmarkBar); - return false; -} - -bool StatusAreaView::IsCommandIdEnabled(int command_id) const { - Browser* browser = browser_view_->browser(); - if (command_id == IDC_RESTORE_TAB) - return browser->CanRestoreTab(); - return browser->command_updater()->IsCommandEnabled(command_id); -} - -bool StatusAreaView::GetAcceleratorForCommandId( - int command_id, - menus::Accelerator* accelerator) { - return false; -} - -void StatusAreaView::ExecuteCommand(int command_id) { - browser_view_->browser()->ExecuteCommand(command_id); -} - -void StatusAreaView::RunMenu(views::View* source, const gfx::Point& pt) { - app_menu_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); -} - } // namespace chromeos diff --git a/chrome/browser/chromeos/status_area_view.h b/chrome/browser/chromeos/status_area_view.h index 1eb9e10..bc2a758 100644 --- a/chrome/browser/chromeos/status_area_view.h +++ b/chrome/browser/chromeos/status_area_view.h @@ -5,29 +5,20 @@ #ifndef CHROME_BROWSER_CHROMEOS_STATUS_AREA_VIEW_H_ #define CHROME_BROWSER_CHROMEOS_STATUS_AREA_VIEW_H_ -#include "app/gfx/native_widget_types.h" -#include "app/menus/simple_menu_model.h" #include "base/basictypes.h" -#include "views/controls/menu/view_menu_delegate.h" -#include "views/controls/menu/menu_2.h" #include "views/view.h" -class AppMenuModel; -class BrowserView; - namespace chromeos { class ClockMenuButton; class LanguageMenuButton; class NetworkMenuButton; class PowerMenuButton; -class StatusAreaButton; +class StatusAreaHost; // This class is used to wrap the small informative widgets in the upper-right // of the window title bar. It is used on ChromeOS only. -class StatusAreaView : public views::View, - public menus::SimpleMenuModel::Delegate, - public views::ViewMenuDelegate { +class StatusAreaView : public views::View { public: enum OpenTabsMode { OPEN_TABS_ON_LEFT = 1, @@ -35,18 +26,15 @@ class StatusAreaView : public views::View, OPEN_TABS_ON_RIGHT }; - explicit StatusAreaView(BrowserView* browser_view); + explicit StatusAreaView(StatusAreaHost* host); virtual ~StatusAreaView() {} - void Init(); + virtual void Init(); // Called when the compact navigation bar mode has changed to // toggle the app menu visibility. void Update(); - // Creates an AppMenuModel for chromeos. - AppMenuModel* CreateAppMenuModel(menus::SimpleMenuModel::Delegate* delegate); - // views::View* overrides. virtual gfx::Size GetPreferredSize(); virtual void Layout(); @@ -55,29 +43,12 @@ class StatusAreaView : public views::View, static void SetOpenTabsMode(OpenTabsMode mode); private: - - // menus::SimpleMenuModel::Delegate implementation. - virtual bool IsCommandIdChecked(int command_id) const; - virtual bool IsCommandIdEnabled(int command_id) const; - virtual bool GetAcceleratorForCommandId(int command_id, - menus::Accelerator* accelerator); - virtual void ExecuteCommand(int command_id); - - // views::ViewMenuDelegate implementation. - virtual void RunMenu(views::View* source, const gfx::Point& pt); - - // The browser window that owns us. - BrowserView* browser_view_; + StatusAreaHost* host_; ClockMenuButton* clock_view_; LanguageMenuButton* language_view_; NetworkMenuButton* network_view_; - PowerMenuButton* battery_view_; - StatusAreaButton* menu_view_; - - scoped_ptr<menus::SimpleMenuModel> app_menu_contents_; - scoped_ptr<menus::SimpleMenuModel> options_menu_contents_; - scoped_ptr<views::Menu2> app_menu_menu_; + PowerMenuButton* power_view_; static OpenTabsMode open_tabs_mode_; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 1e14b7a..6b2f41a 100755 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -257,6 +257,8 @@ 'browser/chrome_thread.h', 'browser/chromeos/browser_notification_observers.cc', 'browser/chromeos/browser_extenders.cc', + 'browser/chromeos/browser_status_area_view.cc', + 'browser/chromeos/browser_status_area_view.h', 'browser/chromeos/chromeos_browser_view.cc', 'browser/chromeos/chromeos_browser_view.h', 'browser/chromeos/clock_menu_button.cc', @@ -322,6 +324,7 @@ 'browser/chromeos/settings_page_view.h', 'browser/chromeos/status_area_button.cc', 'browser/chromeos/status_area_button.h', + 'browser/chromeos/status_area_host.h', 'browser/chromeos/status_area_view.cc', 'browser/chromeos/status_area_view.h', 'browser/chromeos/synaptics_library.cc', |