Commit 70091e75 authored by jialiul's avatar jialiul Committed by Commit bot

Bug fix for the pointer lock string problem, including:

(1) make the tile of the denyButton adaptive, such that
 "Deny" will show on a mouse lock request instead of "Exit full screen."
(2) add unittest to verify its behavior.

XIB changes:
* Remove the default deny button title IDS_FULLSCREEN_EXIT_FULLSCREEN.

BUG=139944

Review URL: https://codereview.chromium.org/856253002

Cr-Commit-Position: refs/heads/master@{#313638}
parent e5ec4c67
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
<object class="NSButtonCell" key="NSCell" id="39119561"> <object class="NSButtonCell" key="NSCell" id="39119561">
<int key="NSCellFlags">67108864</int> <int key="NSCellFlags">67108864</int>
<int key="NSCellFlags2">134217728</int> <int key="NSCellFlags2">134217728</int>
<string key="NSContents">^IDS_FULLSCREEN_EXIT_FULLSCREEN</string> <string key="NSContents"></string>
<object class="NSFont" key="NSSupport" id="199487396"> <object class="NSFont" key="NSSupport" id="199487396">
<string key="NSName">LucidaGrande</string> <string key="NSName">LucidaGrande</string>
<double key="NSSize">13</double> <double key="NSSize">13</double>
......
...@@ -44,8 +44,9 @@ const float kHideDuration = 0.7; ...@@ -44,8 +44,9 @@ const float kHideDuration = 0.7;
@interface ExclusiveAccessBubbleWindowController (PrivateMethods) @interface ExclusiveAccessBubbleWindowController (PrivateMethods)
// Sets |exitLabel_| based on |exitLabelPlaceholder_|, // Sets |exitLabel_| based on |exitLabelPlaceholder_|,
// sets |exitLabelPlaceholder_| to nil. // sets |exitLabelPlaceholder_| to nil,
- (void)initializeLabel; // sets |denyButton_| text based on |bubbleType_|.
- (void)initializeLabelAndButton;
- (NSString*)getLabelText; - (NSString*)getLabelText;
...@@ -121,7 +122,6 @@ const float kHideDuration = 0.7; ...@@ -121,7 +122,6 @@ const float kHideDuration = 0.7;
InfoBubbleWindow* info_bubble = static_cast<InfoBubbleWindow*>([self window]); InfoBubbleWindow* info_bubble = static_cast<InfoBubbleWindow*>([self window]);
[info_bubble setCanBecomeKeyWindow:NO]; [info_bubble setCanBecomeKeyWindow:NO];
if (!exclusive_access_bubble::ShowButtonsForType(bubbleType_)) { if (!exclusive_access_bubble::ShowButtonsForType(bubbleType_)) {
[self showButtons:NO];
[self hideSoon]; [self hideSoon];
} }
[tweaker_ tweakUI:info_bubble]; [tweaker_ tweakUI:info_bubble];
...@@ -134,7 +134,7 @@ const float kHideDuration = 0.7; ...@@ -134,7 +134,7 @@ const float kHideDuration = 0.7;
- (void)awakeFromNib { - (void)awakeFromNib {
DCHECK([[self window] isKindOfClass:[InfoBubbleWindow class]]); DCHECK([[self window] isKindOfClass:[InfoBubbleWindow class]]);
[messageLabel_ setStringValue:[self getLabelText]]; [messageLabel_ setStringValue:[self getLabelText]];
[self initializeLabel]; [self initializeLabelAndButton];
} }
- (void)positionInWindowAtTop:(CGFloat)maxY width:(CGFloat)maxWidth { - (void)positionInWindowAtTop:(CGFloat)maxY width:(CGFloat)maxWidth {
...@@ -198,7 +198,7 @@ const float kHideDuration = 0.7; ...@@ -198,7 +198,7 @@ const float kHideDuration = 0.7;
@implementation ExclusiveAccessBubbleWindowController (PrivateMethods) @implementation ExclusiveAccessBubbleWindowController (PrivateMethods)
- (void)initializeLabel { - (void)initializeLabelAndButton {
// Replace the label placeholder NSTextField with the real label NSTextView. // Replace the label placeholder NSTextField with the real label NSTextView.
// The former doesn't show links in a nice way, but the latter can't be added // The former doesn't show links in a nice way, but the latter can't be added
// in IB without a containing scroll view, so create the NSTextView // in IB without a containing scroll view, so create the NSTextView
...@@ -259,6 +259,17 @@ const float kHideDuration = 0.7; ...@@ -259,6 +259,17 @@ const float kHideDuration = 0.7;
labelFrame.origin.x += NSWidth(labelFrame) - NSWidth(textFrame); labelFrame.origin.x += NSWidth(labelFrame) - NSWidth(textFrame);
labelFrame.size = textFrame.size; labelFrame.size = textFrame.size;
[exitLabel_ setFrame:labelFrame]; [exitLabel_ setFrame:labelFrame];
// Update the title of denyButton_ according to the current bubbleType_,
// or show no button at all.
if (exclusive_access_bubble::ShowButtonsForType(bubbleType_)) {
NSString* denyButtonText =
SysUTF16ToNSString(
exclusive_access_bubble::GetDenyButtonTextForType(bubbleType_));
[denyButton_ setTitle:denyButtonText];
} else {
[self showButtons:NO];
}
} }
- (NSString*)getLabelText { - (NSString*)getLabelText {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "chrome/browser/ui/cocoa/browser_window_controller.h" #include "chrome/browser/ui/cocoa/browser_window_controller.h"
#include "chrome/browser/ui/cocoa/cocoa_profile_test.h" #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/site_instance.h" #include "content/public/browser/site_instance.h"
...@@ -17,6 +18,8 @@ ...@@ -17,6 +18,8 @@
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "testing/gtest_mac.h" #include "testing/gtest_mac.h"
#include "ui/base/accelerators/platform_accelerator_cocoa.h" #include "ui/base/accelerators/platform_accelerator_cocoa.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h"
using content::SiteInstance; using content::SiteInstance;
using content::WebContents; using content::WebContents;
...@@ -26,11 +29,13 @@ using content::WebContents; ...@@ -26,11 +29,13 @@ using content::WebContents;
+ (NSString*)keyCommandString; + (NSString*)keyCommandString;
+ (NSString*)keyCombinationForAccelerator: + (NSString*)keyCombinationForAccelerator:
(const ui::PlatformAcceleratorCocoa&)item; (const ui::PlatformAcceleratorCocoa&)item;
- (void)initializeLabelAndButton;
@end @end
@interface ExclusiveAccessBubbleWindowController (ExposedForTesting) @interface ExclusiveAccessBubbleWindowController (ExposedForTesting)
- (NSTextField*)exitLabelPlaceholder; - (NSTextField*)exitLabelPlaceholder;
- (NSTextView*)exitLabel; - (NSTextView*)exitLabel;
- (NSString*)denyButtonText;
@end @end
@implementation ExclusiveAccessBubbleWindowController (ExposedForTesting) @implementation ExclusiveAccessBubbleWindowController (ExposedForTesting)
...@@ -41,6 +46,10 @@ using content::WebContents; ...@@ -41,6 +46,10 @@ using content::WebContents;
- (NSTextView*)exitLabel { - (NSTextView*)exitLabel {
return exitLabel_; return exitLabel_;
} }
- (NSString*)denyButtonText {
return [denyButton_ title];
}
@end @end
class ExclusiveAccessBubbleWindowControllerTest : public CocoaProfileTest { class ExclusiveAccessBubbleWindowControllerTest : public CocoaProfileTest {
...@@ -129,3 +138,27 @@ TEST_F(ExclusiveAccessBubbleWindowControllerTest, ShortcutText) { ...@@ -129,3 +138,27 @@ TEST_F(ExclusiveAccessBubbleWindowControllerTest, ShortcutText) {
EXPECT_NSEQ(cmd_shift_f_text, cmd_F_text); EXPECT_NSEQ(cmd_shift_f_text, cmd_F_text);
EXPECT_NSEQ(@"\u2318\u21E7F", cmd_shift_f_text); EXPECT_NSEQ(@"\u2318\u21E7F", cmd_shift_f_text);
} }
// http://crbug.com/139944
TEST_F(ExclusiveAccessBubbleWindowControllerTest, DenyButtonText) {
controller_.reset([[ExclusiveAccessBubbleWindowController alloc]
initWithOwner:nil
browser:browser()
url:GURL()
bubbleType:EXCLUSIVE_ACCESS_BUBBLE_TYPE_MOUSELOCK_BUTTONS]);
[controller_ initializeLabelAndButton];
NSString* mouselock_deny_button_text = [controller_ denyButtonText];
EXPECT_NSEQ(l10n_util::GetNSString(IDS_FULLSCREEN_DENY),
mouselock_deny_button_text);
controller_.reset([[ExclusiveAccessBubbleWindowController alloc]
initWithOwner:nil
browser:browser()
url:GURL()
bubbleType:EXCLUSIVE_ACCESS_BUBBLE_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS]);
[controller_ initializeLabelAndButton];
NSString* fullscreen_mouselock_deny_button_text =
[controller_ denyButtonText];
EXPECT_NSEQ(l10n_util::GetNSString(IDS_FULLSCREEN_EXIT),
fullscreen_mouselock_deny_button_text);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment