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

Side by Side Diff: chrome/browser/ui/views/frame/browser_frame.cc

Issue 11819008: Refactors building the system menu model into a common place (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to trunk and fix windows build Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/ui/views/frame/browser_frame.h" 5 #include "chrome/browser/ui/views/frame/browser_frame.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "base/chromeos/chromeos_version.h" 8 #include "base/chromeos/chromeos_version.h"
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "chrome/browser/themes/theme_service.h" 10 #include "chrome/browser/themes/theme_service.h"
11 #include "chrome/browser/themes/theme_service_factory.h" 11 #include "chrome/browser/themes/theme_service_factory.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_list.h" 13 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/browser/ui/browser_window_state.h" 14 #include "chrome/browser/ui/browser_window_state.h"
15 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h" 15 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h"
16 #include "chrome/browser/ui/views/frame/browser_root_view.h" 16 #include "chrome/browser/ui/views/frame/browser_root_view.h"
17 #include "chrome/browser/ui/views/frame/browser_view.h" 17 #include "chrome/browser/ui/views/frame/browser_view.h"
18 #include "chrome/browser/ui/views/frame/native_browser_frame.h" 18 #include "chrome/browser/ui/views/frame/native_browser_frame.h"
19 #include "chrome/browser/ui/views/frame/system_menu_model_builder.h"
19 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
20 #include "ui/aura/root_window.h" 21 #include "ui/aura/root_window.h"
21 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
23 #include "ui/base/hit_test.h"
22 #include "ui/base/theme_provider.h" 24 #include "ui/base/theme_provider.h"
23 #include "ui/gfx/screen.h" 25 #include "ui/gfx/screen.h"
26 #include "ui/views/controls/menu/menu_model_adapter.h"
27 #include "ui/views/controls/menu/menu_runner.h"
24 #include "ui/views/widget/native_widget.h" 28 #include "ui/views/widget/native_widget.h"
25 29
26 #if defined(OS_WIN) && !defined(USE_AURA) 30 #if defined(OS_WIN) && !defined(USE_AURA)
27 #include "chrome/browser/ui/views/frame/glass_browser_frame_view.h" 31 #include "chrome/browser/ui/views/frame/glass_browser_frame_view.h"
28 #endif 32 #endif
29 33
30 //////////////////////////////////////////////////////////////////////////////// 34 ////////////////////////////////////////////////////////////////////////////////
31 // BrowserFrame, public: 35 // BrowserFrame, public:
32 36
33 BrowserFrame::BrowserFrame(BrowserView* browser_view) 37 BrowserFrame::BrowserFrame(BrowserView* browser_view)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 params.type = views::Widget::InitParams::TYPE_PANEL; 69 params.type = views::Widget::InitParams::TYPE_PANEL;
66 } 70 }
67 #if defined(USE_ASH) 71 #if defined(USE_ASH)
68 if (browser_view_->browser()->host_desktop_type() == 72 if (browser_view_->browser()->host_desktop_type() ==
69 chrome::HOST_DESKTOP_TYPE_ASH) { 73 chrome::HOST_DESKTOP_TYPE_ASH) {
70 params.context = ash::Shell::GetAllRootWindows()[0]; 74 params.context = ash::Shell::GetAllRootWindows()[0];
71 } 75 }
72 #endif 76 #endif
73 Init(params); 77 Init(params);
74 78
75 native_browser_frame_->InitSystemContextMenu(); 79 if (!native_browser_frame_->UsesNativeSystemMenu()) {
80 DCHECK(non_client_view());
81 non_client_view()->set_context_menu_controller(this);
82 }
76 } 83 }
77 84
78 int BrowserFrame::GetMinimizeButtonOffset() const { 85 int BrowserFrame::GetMinimizeButtonOffset() const {
79 return native_browser_frame_->GetMinimizeButtonOffset(); 86 return native_browser_frame_->GetMinimizeButtonOffset();
80 } 87 }
81 88
82 gfx::Rect BrowserFrame::GetBoundsForTabStrip(views::View* tabstrip) const { 89 gfx::Rect BrowserFrame::GetBoundsForTabStrip(views::View* tabstrip) const {
83 return browser_frame_view_->GetBoundsForTabStrip(tabstrip); 90 return browser_frame_view_->GetBoundsForTabStrip(tabstrip);
84 } 91 }
85 92
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // active on the users desktop, then none of the windows contained in the 146 // active on the users desktop, then none of the windows contained in the
140 // remote desktop will be activated. However, NativeWidgetWin::Activate() 147 // remote desktop will be activated. However, NativeWidgetWin::Activate()
141 // will still bring this browser window to the foreground. We explicitly 148 // will still bring this browser window to the foreground. We explicitly
142 // set ourselves as the last active browser window to ensure that we get 149 // set ourselves as the last active browser window to ensure that we get
143 // treated as such by the rest of Chrome. 150 // treated as such by the rest of Chrome.
144 BrowserList::SetLastActive(browser_view_->browser()); 151 BrowserList::SetLastActive(browser_view_->browser());
145 } 152 }
146 Widget::OnNativeWidgetActivationChanged(active); 153 Widget::OnNativeWidgetActivationChanged(active);
147 } 154 }
148 155
156 void BrowserFrame::ShowContextMenuForView(views::View* source,
157 const gfx::Point& p) {
158 // Only show context menu if point is in unobscured parts of browser, i.e.
159 // if NonClientHitTest returns :
160 // - HTCAPTION: in title bar or unobscured part of tabstrip
161 // - HTNOWHERE: as the name implies.
162 gfx::Point point_in_view_coords(p);
163 views::View::ConvertPointFromScreen(non_client_view(), &point_in_view_coords);
164 int hit_test = non_client_view()->NonClientHitTest(point_in_view_coords);
165 if (hit_test == HTCAPTION || hit_test == HTNOWHERE) {
166 views::MenuModelAdapter menu_adapter(GetSystemMenuModel());
167 menu_runner_.reset(new views::MenuRunner(menu_adapter.CreateMenu()));
168 if (menu_runner_->RunMenuAt(source->GetWidget(), NULL,
169 gfx::Rect(p, gfx::Size(0,0)), views::MenuItemView::TOPLEFT,
170 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) ==
171 views::MenuRunner::MENU_DELETED)
172 return;
173 }
174 }
175
176 ui::MenuModel* BrowserFrame::GetSystemMenuModel() {
177 if (!menu_model_builder_.get()) {
178 menu_model_builder_.reset(
179 new SystemMenuModelBuilder(browser_view_, browser_view_->browser()));
180 menu_model_builder_->Init();
181 }
182 return menu_model_builder_->menu_model();
183 }
184
149 AvatarMenuButton* BrowserFrame::GetAvatarMenuButton() { 185 AvatarMenuButton* BrowserFrame::GetAvatarMenuButton() {
150 return browser_frame_view_->avatar_button(); 186 return browser_frame_view_->avatar_button();
151 } 187 }
152 188
153 #if !defined(OS_WIN) || defined(USE_AURA) 189 #if !defined(OS_WIN) || defined(USE_AURA)
154 bool BrowserFrame::ShouldLeaveOffsetNearTopBorder() { 190 bool BrowserFrame::ShouldLeaveOffsetNearTopBorder() {
155 return !IsMaximized(); 191 return !IsMaximized();
156 } 192 }
157 #endif // OS_WIN 193 #endif // OS_WIN
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_frame.h ('k') | chrome/browser/ui/views/frame/browser_frame_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698