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

Side by Side Diff: chrome/browser/ui/views/frame/browser_frame_aura.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_aura.h" 5 #include "chrome/browser/ui/views/frame/browser_frame_aura.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/ui/views/frame/browser_view.h" 9 #include "chrome/browser/ui/views/frame/browser_view.h"
10 #include "chrome/browser/ui/views/frame/system_menu_model_delegate.h"
11 #include "grit/chromium_strings.h" 10 #include "grit/chromium_strings.h"
12 #include "grit/generated_resources.h" 11 #include "grit/generated_resources.h"
13 #include "ui/aura/client/aura_constants.h" 12 #include "ui/aura/client/aura_constants.h"
14 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
15 #include "ui/aura/window_observer.h" 14 #include "ui/aura/window_observer.h"
16 #include "ui/base/hit_test.h" 15 #include "ui/base/hit_test.h"
17 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/base/models/simple_menu_model.h"
19 #include "ui/gfx/font.h" 17 #include "ui/gfx/font.h"
20 #include "ui/views/controls/menu/menu_model_adapter.h"
21 #include "ui/views/controls/menu/menu_runner.h"
22 #include "ui/views/view.h" 18 #include "ui/views/view.h"
23 19
24 #if defined(USE_ASH) 20 #if defined(USE_ASH)
25 #include "ash/wm/property_util.h" 21 #include "ash/wm/property_util.h"
26 #include "ash/wm/window_util.h" 22 #include "ash/wm/window_util.h"
27 #endif 23 #endif
28 24
29 #if !defined(OS_CHROMEOS) 25 #if !defined(OS_CHROMEOS)
30 #include "chrome/browser/ui/views/frame/desktop_browser_frame_aura.h" 26 #include "chrome/browser/ui/views/frame/desktop_browser_frame_aura.h"
31 #endif 27 #endif
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 108 }
113 // Turn on auto window management if we don't need an explicit bounds. 109 // Turn on auto window management if we don't need an explicit bounds.
114 // This way the requested bounds are honored. 110 // This way the requested bounds are honored.
115 if (!browser_view->browser()->bounds_overridden() && 111 if (!browser_view->browser()->bounds_overridden() &&
116 !browser_view->browser()->is_session_restore()) 112 !browser_view->browser()->is_session_restore())
117 SetWindowAutoManaged(); 113 SetWindowAutoManaged();
118 #endif 114 #endif
119 } 115 }
120 116
121 /////////////////////////////////////////////////////////////////////////////// 117 ///////////////////////////////////////////////////////////////////////////////
122 // BrowserFrameAura, views::ContextMenuController overrides:
123 void BrowserFrameAura::ShowContextMenuForView(views::View* source,
124 const gfx::Point& p) {
125 // Only show context menu if point is in unobscured parts of browser, i.e.
126 // if NonClientHitTest returns :
127 // - HTCAPTION: in title bar or unobscured part of tabstrip
128 // - HTNOWHERE: as the name implies.
129 views::NonClientView* non_client_view = browser_view()->frame()->
130 non_client_view();
131 gfx::Point point_in_view_coords(p);
132 views::View::ConvertPointFromScreen(non_client_view, &point_in_view_coords);
133 int hit_test = non_client_view->NonClientHitTest(point_in_view_coords);
134 if (hit_test == HTCAPTION || hit_test == HTNOWHERE) {
135 SystemMenuModelDelegate menu_delegate(browser_view(),
136 browser_view()->browser());
137 ui::SimpleMenuModel model(&menu_delegate);
138 model.AddItemWithStringId(IDC_RESTORE_TAB, IDS_RESTORE_TAB);
139 model.AddItemWithStringId(IDC_NEW_TAB, IDS_NEW_TAB);
140 model.AddSeparator(ui::NORMAL_SEPARATOR);
141 model.AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER);
142 views::MenuModelAdapter menu_adapter(&model);
143 menu_runner_.reset(new views::MenuRunner(menu_adapter.CreateMenu()));
144
145 if (menu_runner_->RunMenuAt(source->GetWidget(), NULL,
146 gfx::Rect(p, gfx::Size(0,0)), views::MenuItemView::TOPLEFT,
147 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU) ==
148 views::MenuRunner::MENU_DELETED)
149 return;
150 }
151 }
152
153 ///////////////////////////////////////////////////////////////////////////////
154 // BrowserFrameAura, views::NativeWidgetAura overrides: 118 // BrowserFrameAura, views::NativeWidgetAura overrides:
155 119
156 void BrowserFrameAura::OnWindowDestroying() { 120 void BrowserFrameAura::OnWindowDestroying() {
157 // Window is destroyed before our destructor is called, so clean up our 121 // Window is destroyed before our destructor is called, so clean up our
158 // observer here. 122 // observer here.
159 GetNativeWindow()->RemoveObserver(window_property_watcher_.get()); 123 GetNativeWindow()->RemoveObserver(window_property_watcher_.get());
160 views::NativeWidgetAura::OnWindowDestroying(); 124 views::NativeWidgetAura::OnWindowDestroying();
161 } 125 }
162 126
163 void BrowserFrameAura::OnWindowTargetVisibilityChanged(bool visible) { 127 void BrowserFrameAura::OnWindowTargetVisibilityChanged(bool visible) {
(...skipping 16 matching lines...) Expand all
180 // BrowserFrameAura, NativeBrowserFrame implementation: 144 // BrowserFrameAura, NativeBrowserFrame implementation:
181 145
182 views::NativeWidget* BrowserFrameAura::AsNativeWidget() { 146 views::NativeWidget* BrowserFrameAura::AsNativeWidget() {
183 return this; 147 return this;
184 } 148 }
185 149
186 const views::NativeWidget* BrowserFrameAura::AsNativeWidget() const { 150 const views::NativeWidget* BrowserFrameAura::AsNativeWidget() const {
187 return this; 151 return this;
188 } 152 }
189 153
190 void BrowserFrameAura::InitSystemContextMenu() { 154 bool BrowserFrameAura::UsesNativeSystemMenu() const {
191 views::NonClientView* non_client_view = 155 return false;
192 browser_view()->frame()->non_client_view();
193 DCHECK(non_client_view);
194 non_client_view->set_context_menu_controller(this);
195 } 156 }
196 157
197 int BrowserFrameAura::GetMinimizeButtonOffset() const { 158 int BrowserFrameAura::GetMinimizeButtonOffset() const {
198 return 0; 159 return 0;
199 } 160 }
200 161
201 void BrowserFrameAura::TabStripDisplayModeChanged() { 162 void BrowserFrameAura::TabStripDisplayModeChanged() {
202 } 163 }
203 164
204 //////////////////////////////////////////////////////////////////////////////// 165 ////////////////////////////////////////////////////////////////////////////////
(...skipping 26 matching lines...) Expand all
231 BrowserFrameAura::~BrowserFrameAura() { 192 BrowserFrameAura::~BrowserFrameAura() {
232 } 193 }
233 194
234 void BrowserFrameAura::SetWindowAutoManaged() { 195 void BrowserFrameAura::SetWindowAutoManaged() {
235 #if defined(USE_ASH) 196 #if defined(USE_ASH)
236 if (browser_view_->browser()->type() != Browser::TYPE_POPUP || 197 if (browser_view_->browser()->type() != Browser::TYPE_POPUP ||
237 browser_view_->browser()->is_app()) 198 browser_view_->browser()->is_app())
238 ash::wm::SetWindowPositionManaged(GetNativeWindow(), true); 199 ash::wm::SetWindowPositionManaged(GetNativeWindow(), true);
239 #endif 200 #endif
240 } 201 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_frame_aura.h ('k') | chrome/browser/ui/views/frame/browser_frame_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698