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

Side by Side Diff: chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm

Issue 682113002: Fix accelerators in avatar gaia webview on mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" 7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
8 8
9 #include "base/mac/bundle_locations.h" 9 #include "base/mac/bundle_locations.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 #import "ui/base/cocoa/hover_image_button.h" 63 #import "ui/base/cocoa/hover_image_button.h"
64 #include "ui/base/cocoa/window_size_constants.h" 64 #include "ui/base/cocoa/window_size_constants.h"
65 #include "ui/base/l10n/l10n_util.h" 65 #include "ui/base/l10n/l10n_util.h"
66 #include "ui/base/l10n/l10n_util_mac.h" 66 #include "ui/base/l10n/l10n_util_mac.h"
67 #include "ui/base/resource/resource_bundle.h" 67 #include "ui/base/resource/resource_bundle.h"
68 #include "ui/gfx/image/image.h" 68 #include "ui/gfx/image/image.h"
69 #include "ui/gfx/text_elider.h" 69 #include "ui/gfx/text_elider.h"
70 #include "ui/native_theme/common_theme.h" 70 #include "ui/native_theme/common_theme.h"
71 #include "ui/native_theme/native_theme.h" 71 #include "ui/native_theme/native_theme.h"
72 72
73 #include "chrome/app/chrome_command_ids.h"
74 #include "content/public/browser/native_web_keyboard_event.h"
75 #import "chrome/browser/ui/cocoa/browser_window_utils.h"
76
73 namespace { 77 namespace {
74 78
75 // Constants taken from the Windows/Views implementation at: 79 // Constants taken from the Windows/Views implementation at:
76 // chrome/browser/ui/views/profile_chooser_view.cc 80 // chrome/browser/ui/views/profile_chooser_view.cc
77 const int kLargeImageSide = 88; 81 const int kLargeImageSide = 88;
78 const int kSmallImageSide = 32; 82 const int kSmallImageSide = 32;
79 const CGFloat kFixedMenuWidth = 250; 83 const CGFloat kFixedMenuWidth = 250;
80 84
81 const CGFloat kVerticalSpacing = 16.0; 85 const CGFloat kVerticalSpacing = 16.0;
82 const CGFloat kSmallVerticalSpacing = 10.0; 86 const CGFloat kSmallVerticalSpacing = 10.0;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 244 }
241 245
242 bool HasAuthError(Profile* profile) { 246 bool HasAuthError(Profile* profile) {
243 const SigninErrorController* error_controller = 247 const SigninErrorController* error_controller =
244 profiles::GetSigninErrorController(profile); 248 profiles::GetSigninErrorController(profile);
245 return error_controller && error_controller->HasError(); 249 return error_controller && error_controller->HasError();
246 } 250 }
247 251
248 } // namespace 252 } // namespace
249 253
254 // Custom WebContentsDelegate that allows handling of hotkeys and suppresses
255 // the context menu
256 class GaiaWebContentsDelegate : public content::WebContentsDelegate {
257 public:
258 GaiaWebContentsDelegate() {}
259
260 virtual ~GaiaWebContentsDelegate() {}
261
262 private:
263 // Overridden from content::WebContentsDelegate.
264 bool HandleContextMenu(const content::ContextMenuParams& params) override;
265 void HandleKeyboardEvent(
266 content::WebContents* source,
267 const content::NativeWebKeyboardEvent& event) override;
268 };
269
270 bool GaiaWebContentsDelegate::HandleContextMenu(
271 const content::ContextMenuParams& params) {
272 #ifndef NDEBUG
273 return false;
274 #else
275 return true;
276 #endif
277 }
278
279 void GaiaWebContentsDelegate::HandleKeyboardEvent(
280 content::WebContents* source,
281 const content::NativeWebKeyboardEvent& event) {
282 if (![BrowserWindowUtils shouldHandleKeyboardEvent:event])
283 return;
284
285 int chromeCommandId = [BrowserWindowUtils getCommandId:event];
286
287 bool isTextEditingCommand =
288 (event.modifiers & blink::WebInputEvent::MetaKey) &&
289 (event.windowsKeyCode == ui::VKEY_A ||
290 event.windowsKeyCode == ui::VKEY_V);
291
292 // TODO(guohui): maybe should add accelerator for the back button.
293 if (chromeCommandId == IDC_CLOSE_WINDOW || chromeCommandId == IDC_EXIT ||
294 isTextEditingCommand) {
295 [[NSApp mainMenu] performKeyEquivalent:event.os_event];
296 }
297 }
298
250 // Class that listens to changes to the OAuth2Tokens for the active profile, 299 // Class that listens to changes to the OAuth2Tokens for the active profile,
251 // changes to the avatar menu model or browser close notifications. 300 // changes to the avatar menu model or browser close notifications.
252 class ActiveProfileObserverBridge : public AvatarMenuObserver, 301 class ActiveProfileObserverBridge : public AvatarMenuObserver,
253 public content::NotificationObserver, 302 public content::NotificationObserver,
254 public OAuth2TokenService::Observer { 303 public OAuth2TokenService::Observer {
255 public: 304 public:
256 ActiveProfileObserverBridge(ProfileChooserController* controller, 305 ActiveProfileObserverBridge(ProfileChooserController* controller,
257 Browser* browser) 306 Browser* browser)
258 : controller_(controller), 307 : controller_(controller),
259 browser_(browser), 308 browser_(browser),
(...skipping 1638 matching lines...) Expand 10 before | Expand all | Expand 10 after
1898 errorController ? errorController->error_username() : std::string()); 1947 errorController ? errorController->error_username() : std::string());
1899 messageId = IDS_PROFILES_GAIA_REAUTH_TITLE; 1948 messageId = IDS_PROFILES_GAIA_REAUTH_TITLE;
1900 break; 1949 break;
1901 default: 1950 default:
1902 NOTREACHED() << "Called with invalid mode=" << viewMode_; 1951 NOTREACHED() << "Called with invalid mode=" << viewMode_;
1903 break; 1952 break;
1904 } 1953 }
1905 1954
1906 webContents_.reset(content::WebContents::Create( 1955 webContents_.reset(content::WebContents::Create(
1907 content::WebContents::CreateParams(browser_->profile()))); 1956 content::WebContents::CreateParams(browser_->profile())));
1957
1958 webContentsDelegate_.reset(new GaiaWebContentsDelegate());
1959 webContents_->SetDelegate(webContentsDelegate_.get());
1908 webContents_->GetController().LoadURL(url, 1960 webContents_->GetController().LoadURL(url,
1909 content::Referrer(), 1961 content::Referrer(),
1910 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, 1962 ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
1911 std::string()); 1963 std::string());
1912 NSView* webview = webContents_->GetNativeView(); 1964 NSView* webview = webContents_->GetNativeView();
1913 [webview setFrameSize:NSMakeSize(kFixedGaiaViewWidth, kFixedGaiaViewHeight)]; 1965 [webview setFrameSize:NSMakeSize(kFixedGaiaViewWidth, kFixedGaiaViewHeight)];
1914 [container addSubview:webview]; 1966 [container addSubview:webview];
1915 content::RenderWidgetHostView* rwhv = webContents_->GetRenderWidgetHostView(); 1967 content::RenderWidgetHostView* rwhv = webContents_->GetRenderWidgetHostView();
1916 if (rwhv) 1968 if (rwhv)
1917 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor); 1969 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor);
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
2204 } 2256 }
2205 2257
2206 - (bool)shouldShowGoIncognito { 2258 - (bool)shouldShowGoIncognito {
2207 bool incognitoAvailable = 2259 bool incognitoAvailable =
2208 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 2260 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
2209 IncognitoModePrefs::DISABLED; 2261 IncognitoModePrefs::DISABLED;
2210 return incognitoAvailable && !browser_->profile()->IsGuestSession(); 2262 return incognitoAvailable && !browser_->profile()->IsGuestSession();
2211 } 2263 }
2212 2264
2213 @end 2265 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698