| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "app/theme_provider.h" | 7 #include "app/theme_provider.h" |
| 8 #include "chrome/app/chrome_dll_resource.h" | 8 #include "chrome/app/chrome_dll_resource.h" |
| 9 #include "chrome/browser/chromeos/compact_navigation_bar.h" | 9 #include "chrome/browser/chromeos/compact_navigation_bar.h" |
| 10 #include "chrome/browser/chromeos/main_menu.h" | 10 #include "chrome/browser/chromeos/main_menu.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // | 32 // |
| 33 // and adds the system context menu to the remaining arae of the titlebar. | 33 // and adds the system context menu to the remaining arae of the titlebar. |
| 34 // | 34 // |
| 35 // For Browser::TYPE_POPUP type of BrowserView, see PopupExtender class below. | 35 // For Browser::TYPE_POPUP type of BrowserView, see PopupExtender class below. |
| 36 class NormalExtender : public BrowserExtender, | 36 class NormalExtender : public BrowserExtender, |
| 37 public views::ButtonListener, | 37 public views::ButtonListener, |
| 38 public views::ContextMenuController { | 38 public views::ContextMenuController { |
| 39 public: | 39 public: |
| 40 explicit NormalExtender(BrowserView* browser_view) | 40 explicit NormalExtender(BrowserView* browser_view) |
| 41 : BrowserExtender(browser_view), | 41 : BrowserExtender(browser_view), |
| 42 main_menu_(NULL) { | 42 main_menu_(NULL), |
| 43 status_area_(NULL), |
| 44 compact_navigation_bar_(NULL), |
| 45 // CompactNavigationBar is disabled by default. |
| 46 // TODO(oshima): Get this info from preference. |
| 47 compact_navigation_bar_enabled_(false) { |
| 43 } | 48 } |
| 44 virtual ~NormalExtender() {} | 49 virtual ~NormalExtender() {} |
| 45 | 50 |
| 46 protected: | 51 protected: |
| 47 // BrowserExtender overrides. | 52 // BrowserExtender overrides. |
| 48 virtual void Init() { | 53 virtual void Init() { |
| 49 main_menu_ = new views::ImageButton(this); | 54 main_menu_ = new views::ImageButton(this); |
| 50 ThemeProvider* theme_provider = | 55 ThemeProvider* theme_provider = |
| 51 browser_view()->frame()->GetThemeProviderForFrame(); | 56 browser_view()->frame()->GetThemeProviderForFrame(); |
| 52 SkBitmap* image = theme_provider->GetBitmapNamed(IDR_MAIN_MENU_BUTTON); | 57 SkBitmap* image = theme_provider->GetBitmapNamed(IDR_MAIN_MENU_BUTTON); |
| 53 main_menu_->SetImage(views::CustomButton::BS_NORMAL, image); | 58 main_menu_->SetImage(views::CustomButton::BS_NORMAL, image); |
| 54 main_menu_->SetImage(views::CustomButton::BS_HOT, image); | 59 main_menu_->SetImage(views::CustomButton::BS_HOT, image); |
| 55 main_menu_->SetImage(views::CustomButton::BS_PUSHED, image); | 60 main_menu_->SetImage(views::CustomButton::BS_PUSHED, image); |
| 56 browser_view()->AddChildView(main_menu_); | 61 browser_view()->AddChildView(main_menu_); |
| 57 | 62 |
| 58 compact_navigation_bar_ = | 63 compact_navigation_bar_ = |
| 59 new CompactNavigationBar(browser_view()->browser()); | 64 new CompactNavigationBar(browser_view()->browser()); |
| 60 browser_view()->AddChildView(compact_navigation_bar_); | 65 browser_view()->AddChildView(compact_navigation_bar_); |
| 61 compact_navigation_bar_->Init(); | 66 compact_navigation_bar_->Init(); |
| 62 // Disabled by default. | |
| 63 // TODO(oshima): Get this info from preference. | |
| 64 compact_navigation_bar_->SetVisible(false); | |
| 65 | |
| 66 status_area_ = new StatusAreaView( | 67 status_area_ = new StatusAreaView( |
| 67 browser_view()->browser(), | 68 browser_view()->browser(), |
| 68 browser_view()->GetWindow()->GetNativeWindow()); | 69 browser_view()->GetWindow()->GetNativeWindow()); |
| 69 browser_view()->AddChildView(status_area_); | 70 browser_view()->AddChildView(status_area_); |
| 70 status_area_->Init(); | 71 status_area_->Init(); |
| 71 | 72 |
| 72 InitSystemMenu(); | 73 InitSystemMenu(); |
| 73 MainMenu::ScheduleCreation(); | 74 MainMenu::ScheduleCreation(); |
| 74 | 75 |
| 75 // The ContextMenuController has to be set to a NonClientView but | 76 // The ContextMenuController has to be set to a NonClientView but |
| 76 // not to a NonClientFrameView because a TabStrip is not a child of | 77 // not to a NonClientFrameView because a TabStrip is not a child of |
| 77 // a NonClientFrameView even though visually a TabStrip is over a | 78 // a NonClientFrameView even though visually a TabStrip is over a |
| 78 // NonClientFrameView. | 79 // NonClientFrameView. |
| 79 BrowserFrameGtk* gtk_frame = | 80 BrowserFrameGtk* gtk_frame = |
| 80 static_cast<BrowserFrameGtk*>(browser_view()->frame()); | 81 static_cast<BrowserFrameGtk*>(browser_view()->frame()); |
| 81 gtk_frame->GetNonClientView()->SetContextMenuController(this); | 82 gtk_frame->GetNonClientView()->SetContextMenuController(this); |
| 82 } | 83 } |
| 83 | 84 |
| 84 virtual gfx::Rect Layout(const gfx::Rect& bounds) { | 85 virtual gfx::Rect Layout(const gfx::Rect& bounds) { |
| 85 // skip if there is no space to layout. | 86 // Skip if there is no space to layout, or if the browser is in |
| 86 if (bounds.IsEmpty()) | 87 // fullscreen mode. |
| 88 if (bounds.IsEmpty() || browser_view()->IsFullscreen()) { |
| 89 main_menu_->SetVisible(false); |
| 90 compact_navigation_bar_->SetVisible(false); |
| 91 status_area_->SetVisible(false); |
| 87 return bounds; | 92 return bounds; |
| 93 } else { |
| 94 main_menu_->SetVisible(true); |
| 95 compact_navigation_bar_->SetVisible(compact_navigation_bar_enabled_); |
| 96 status_area_->SetVisible(true); |
| 97 } |
| 88 | 98 |
| 89 // Layout main menu before tab strip. | 99 // Layout main menu before tab strip. |
| 90 gfx::Size main_menu_size = main_menu_->GetPreferredSize(); | 100 gfx::Size main_menu_size = main_menu_->GetPreferredSize(); |
| 91 main_menu_->SetBounds(bounds.x(), bounds.y(), | 101 main_menu_->SetBounds(bounds.x(), bounds.y(), |
| 92 main_menu_size.width(), bounds.height()); | 102 main_menu_size.width(), bounds.height()); |
| 93 | 103 |
| 94 // Layout status area after tab strip. | 104 // Layout status area after tab strip. |
| 95 gfx::Size status_size = status_area_->GetPreferredSize(); | 105 gfx::Size status_size = status_area_->GetPreferredSize(); |
| 96 status_area_->SetBounds(bounds.x() + bounds.width() - status_size.width(), | 106 status_area_->SetBounds(bounds.x() + bounds.width() - status_size.width(), |
| 97 bounds.y(), status_size.width(), | 107 bounds.y(), status_size.width(), |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 GTK_WIDGET(GetBrowserWindow()->GetNativeWindow()), | 150 GTK_WIDGET(GetBrowserWindow()->GetNativeWindow()), |
| 141 TabOverviewTypes::WINDOW_TYPE_CHROME_TOPLEVEL, | 151 TabOverviewTypes::WINDOW_TYPE_CHROME_TOPLEVEL, |
| 142 NULL); | 152 NULL); |
| 143 } | 153 } |
| 144 | 154 |
| 145 virtual void Close() {} | 155 virtual void Close() {} |
| 146 | 156 |
| 147 virtual void ActivationChanged() {} | 157 virtual void ActivationChanged() {} |
| 148 | 158 |
| 149 virtual bool ShouldForceHideToolbar() { | 159 virtual bool ShouldForceHideToolbar() { |
| 150 return compact_navigation_bar_->IsVisible(); | 160 return compact_navigation_bar_enabled_; |
| 151 } | 161 } |
| 152 | 162 |
| 153 virtual void ToggleCompactNavigationBar() { | 163 virtual void ToggleCompactNavigationBar() { |
| 154 compact_navigation_bar_->SetVisible(!compact_navigation_bar_->IsVisible()); | 164 compact_navigation_bar_enabled_ = !compact_navigation_bar_enabled_; |
| 155 } | 165 } |
| 156 | 166 |
| 157 private: | 167 private: |
| 158 // Creates system menu. | 168 // Creates system menu. |
| 159 void InitSystemMenu() { | 169 void InitSystemMenu() { |
| 160 system_menu_contents_.reset(new views::SimpleMenuModel(browser_view())); | 170 system_menu_contents_.reset(new views::SimpleMenuModel(browser_view())); |
| 161 system_menu_contents_->AddItemWithStringId(IDC_RESTORE_TAB, | 171 system_menu_contents_->AddItemWithStringId(IDC_RESTORE_TAB, |
| 162 IDS_RESTORE_TAB); | 172 IDS_RESTORE_TAB); |
| 163 system_menu_contents_->AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB); | 173 system_menu_contents_->AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB); |
| 164 system_menu_contents_->AddSeparator(); | 174 system_menu_contents_->AddSeparator(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 186 // Status Area view. | 196 // Status Area view. |
| 187 StatusAreaView* status_area_; | 197 StatusAreaView* status_area_; |
| 188 | 198 |
| 189 // System menus | 199 // System menus |
| 190 scoped_ptr<views::SimpleMenuModel> system_menu_contents_; | 200 scoped_ptr<views::SimpleMenuModel> system_menu_contents_; |
| 191 scoped_ptr<views::Menu2> system_menu_menu_; | 201 scoped_ptr<views::Menu2> system_menu_menu_; |
| 192 | 202 |
| 193 // CompactNavigationBar view. | 203 // CompactNavigationBar view. |
| 194 CompactNavigationBar* compact_navigation_bar_; | 204 CompactNavigationBar* compact_navigation_bar_; |
| 195 | 205 |
| 206 // A toggle flag to show/hide the compact navigation bar. |
| 207 bool compact_navigation_bar_enabled_; |
| 208 |
| 196 DISALLOW_COPY_AND_ASSIGN(NormalExtender); | 209 DISALLOW_COPY_AND_ASSIGN(NormalExtender); |
| 197 }; | 210 }; |
| 198 | 211 |
| 199 // PopupExtender class creates dedicated title window for popup window. | 212 // PopupExtender class creates dedicated title window for popup window. |
| 200 // The size and location of the created title window is controlled by | 213 // The size and location of the created title window is controlled by |
| 201 // by window manager. | 214 // by window manager. |
| 202 class PopupExtender : public BrowserExtender { | 215 class PopupExtender : public BrowserExtender { |
| 203 public: | 216 public: |
| 204 explicit PopupExtender(BrowserView* browser_view) | 217 explicit PopupExtender(BrowserView* browser_view) |
| 205 : BrowserExtender(browser_view) { | 218 : BrowserExtender(browser_view) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 // static | 289 // static |
| 277 BrowserExtender* BrowserExtender::Create(BrowserView* browser_view) { | 290 BrowserExtender* BrowserExtender::Create(BrowserView* browser_view) { |
| 278 BrowserExtender* extender; | 291 BrowserExtender* extender; |
| 279 if (browser_view->browser()->type() & Browser::TYPE_POPUP) | 292 if (browser_view->browser()->type() & Browser::TYPE_POPUP) |
| 280 extender = new PopupExtender(browser_view); | 293 extender = new PopupExtender(browser_view); |
| 281 else | 294 else |
| 282 extender = new NormalExtender(browser_view); | 295 extender = new NormalExtender(browser_view); |
| 283 extender->Init(); | 296 extender->Init(); |
| 284 return extender; | 297 return extender; |
| 285 } | 298 } |
| OLD | NEW |