summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-06 20:37:59 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-06 20:37:59 +0000
commitb5366c1298343e62ce0dc3aea10b44089526eeba (patch)
tree95c5ff2cfad20cc9e425fb3c360a9ac570df2264 /chrome/browser/cocoa
parent1e9499c21c23b52391d952572bd9059df532efcb (diff)
downloadchromium_src-b5366c1298343e62ce0dc3aea10b44089526eeba.zip
chromium_src-b5366c1298343e62ce0dc3aea10b44089526eeba.tar.gz
chromium_src-b5366c1298343e62ce0dc3aea10b44089526eeba.tar.bz2
Mac: Improve content settings dialog in some languages.
xib changes: * Get rid of all GTMWidthBasedTweakers in the xib * Change labels from "clip" to "wrap" BUG=39390 TEST=See bug Review URL: http://codereview.chromium.org/1605013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43753 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/content_settings_dialog_controller.mm33
-rw-r--r--chrome/browser/cocoa/l10n_util.h19
-rw-r--r--chrome/browser/cocoa/l10n_util.mm49
-rw-r--r--chrome/browser/cocoa/preferences_window_controller.mm61
4 files changed, 110 insertions, 52 deletions
diff --git a/chrome/browser/cocoa/content_settings_dialog_controller.mm b/chrome/browser/cocoa/content_settings_dialog_controller.mm
index c3b50d8..88034ff 100644
--- a/chrome/browser/cocoa/content_settings_dialog_controller.mm
+++ b/chrome/browser/cocoa/content_settings_dialog_controller.mm
@@ -13,6 +13,7 @@
#import "chrome/browser/cocoa/content_exceptions_window_controller.h"
#import "chrome/browser/cocoa/cookies_window_controller.h"
#import "chrome/browser/cocoa/geolocation_exceptions_window_controller.h"
+#import "chrome/browser/cocoa/l10n_util.h"
#import "chrome/browser/geolocation/geolocation_content_settings_map.h"
#import "chrome/browser/host_content_settings_map.h"
#include "chrome/browser/pref_service.h"
@@ -22,7 +23,6 @@
#include "chrome/common/url_constants.h"
#include "grit/locale_settings.h"
-
namespace {
// Index of the "enabled" and "disabled" radio group settings in all tabs except
@@ -43,6 +43,25 @@ const NSInteger kGeolocationEnabledIndex = 0;
const NSInteger kGeolocationAskIndex = 1;
const NSInteger kGeolocationDisabledIndex = 2;
+// Walks views in top-down order, wraps each to their current width, and moves
+// the latter ones down to prevernt overlaps.
+CGFloat VerticallyReflowGroup(NSArray* views) {
+ views = [views sortedArrayUsingFunction:cocoa_l10n_util::CompareFrameY
+ context:NULL];
+ CGFloat localVerticalShift = 0;
+ for (NSInteger index = [views count] - 1; index >= 0; --index) {
+ NSView* view = [views objectAtIndex:index];
+ NSSize delta = cocoa_l10n_util::WrapOrSizeToFit(view);
+ localVerticalShift += delta.height;
+ if (localVerticalShift) {
+ NSPoint origin = [view frame].origin;
+ origin.y -= localVerticalShift;
+ [view setFrameOrigin:origin];
+ }
+ }
+ return localVerticalShift;
+}
+
} // namespace
@@ -142,6 +161,18 @@ class PrefObserverBridge : public NotificationObserver {
- (void)awakeFromNib {
DCHECK([self window]);
DCHECK_EQ(self, [[self window] delegate]);
+
+ // Adapt views to potentially long localized strings.
+ CGFloat windowDelta = 0;
+ for (NSTabViewItem* tab in [tabView_ tabViewItems]) {
+ windowDelta = MAX(windowDelta,
+ VerticallyReflowGroup([[tab view] subviews]));
+ }
+
+ NSRect frame = [[self window] frame];
+ frame.origin.y -= windowDelta;
+ frame.size.height += windowDelta;
+ [[self window] setFrame:frame display:NO];
}
// NSWindowDelegate method.
diff --git a/chrome/browser/cocoa/l10n_util.h b/chrome/browser/cocoa/l10n_util.h
new file mode 100644
index 0000000..5e417a1
--- /dev/null
+++ b/chrome/browser/cocoa/l10n_util.h
@@ -0,0 +1,19 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import <Cocoa/Cocoa.h>
+
+namespace cocoa_l10n_util {
+
+// Compare function for -[NSArray sortedArrayUsingFunction:context:] that
+// sorts the views in Y order bottom up. |context| is ignored.
+NSInteger CompareFrameY(id view1, id view2, void* context);
+
+// Helper for tweaking views. If view is a:
+// checkbox, radio group or label: it gets a forced wrap at current size
+// editable field: left as is
+// anything else: do +[GTMUILocalizerAndLayoutTweaker sizeToFitView:]
+NSSize WrapOrSizeToFit(NSView* view);
+
+} // namespace cocoa_l10n_util
diff --git a/chrome/browser/cocoa/l10n_util.mm b/chrome/browser/cocoa/l10n_util.mm
new file mode 100644
index 0000000..91691ed
--- /dev/null
+++ b/chrome/browser/cocoa/l10n_util.mm
@@ -0,0 +1,49 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/cocoa/l10n_util.h"
+
+#import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
+
+namespace cocoa_l10n_util {
+
+NSInteger CompareFrameY(id view1, id view2, void* context) {
+ CGFloat y1 = NSMinY([view1 frame]);
+ CGFloat y2 = NSMinY([view2 frame]);
+ if (y1 < y2)
+ return NSOrderedAscending;
+ else if (y1 > y2)
+ return NSOrderedDescending;
+ else
+ return NSOrderedSame;
+}
+
+NSSize WrapOrSizeToFit(NSView* view) {
+ if ([view isKindOfClass:[NSTextField class]]) {
+ NSTextField* textField = static_cast<NSTextField*>(view);
+ if ([textField isEditable])
+ return NSZeroSize;
+ CGFloat heightChange =
+ [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:textField];
+ return NSMakeSize(0.0, heightChange);
+ }
+ if ([view isKindOfClass:[NSMatrix class]]) {
+ NSMatrix* radioGroup = static_cast<NSMatrix*>(view);
+ [GTMUILocalizerAndLayoutTweaker wrapRadioGroupForWidth:radioGroup];
+ return [GTMUILocalizerAndLayoutTweaker sizeToFitView:view];
+ }
+ if ([view isKindOfClass:[NSButton class]]) {
+ NSButton* button = static_cast<NSButton*>(view);
+ NSButtonCell* buttonCell = [button cell];
+ // Decide it's a checkbox via showsStateBy and highlightsBy.
+ if (([buttonCell showsStateBy] == NSCellState) &&
+ ([buttonCell highlightsBy] == NSCellState)) {
+ [GTMUILocalizerAndLayoutTweaker wrapButtonTitleForWidth:button];
+ return [GTMUILocalizerAndLayoutTweaker sizeToFitView:view];
+ }
+ }
+ return [GTMUILocalizerAndLayoutTweaker sizeToFitView:view];
+}
+
+} // namespace cocoa_l10n_util
diff --git a/chrome/browser/cocoa/preferences_window_controller.mm b/chrome/browser/cocoa/preferences_window_controller.mm
index cfe80bf..0e4fbf1 100644
--- a/chrome/browser/cocoa/preferences_window_controller.mm
+++ b/chrome/browser/cocoa/preferences_window_controller.mm
@@ -25,6 +25,7 @@
#import "chrome/browser/cocoa/font_language_settings_controller.h"
#import "chrome/browser/cocoa/import_settings_dialog.h"
#import "chrome/browser/cocoa/keyword_editor_cocoa_controller.h"
+#import "chrome/browser/cocoa/l10n_util.h"
#import "chrome/browser/cocoa/search_engine_list_model.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/metrics/metrics_service.h"
@@ -87,37 +88,6 @@ CGFloat SizeToFitButtonPair(NSButton* leftButton, NSButton* rightButton) {
return widthShift;
}
-// Helper for tweaking the prefs window, if view is a:
-// checkbox, radio group or label: it gets a forced wrap at current size
-// editable field: left as is
-// anything else: do +[GTMUILocalizerAndLayoutTweaker sizeToFitView:]
-NSSize WrapOrSizeToFit(NSView* view) {
- if ([view isKindOfClass:[NSTextField class]]) {
- NSTextField* textField = static_cast<NSTextField*>(view);
- if ([textField isEditable])
- return NSZeroSize;
- CGFloat heightChange =
- [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:textField];
- return NSMakeSize(0.0, heightChange);
- }
- if ([view isKindOfClass:[NSMatrix class]]) {
- NSMatrix* radioGroup = static_cast<NSMatrix*>(view);
- [GTMUILocalizerAndLayoutTweaker wrapRadioGroupForWidth:radioGroup];
- return [GTMUILocalizerAndLayoutTweaker sizeToFitView:view];
- }
- if ([view isKindOfClass:[NSButton class]]) {
- NSButton* button = static_cast<NSButton*>(view);
- NSButtonCell* buttonCell = [button cell];
- // Decide it's a checkbox via showsStateBy and highlightsBy.
- if (([buttonCell showsStateBy] == NSCellState) &&
- ([buttonCell highlightsBy] == NSCellState)) {
- [GTMUILocalizerAndLayoutTweaker wrapButtonTitleForWidth:button];
- return [GTMUILocalizerAndLayoutTweaker sizeToFitView:view];
- }
- }
- return [GTMUILocalizerAndLayoutTweaker sizeToFitView:view];
-}
-
// The different behaviors for the "pref group" auto sizing.
enum AutoSizeGroupBehavior {
kAutoSizeGroupBehaviorVerticalToFit,
@@ -150,7 +120,7 @@ CGFloat AutoSizeGroup(NSArray* views, AutoSizeGroupBehavior behavior,
// Walk bottom up doing the sizing and moves.
for (NSUInteger index = [views count] - 1; index > 0; --index) {
NSView* view = [views objectAtIndex:index];
- NSSize delta = WrapOrSizeToFit(view);
+ NSSize delta = cocoa_l10n_util::WrapOrSizeToFit(view);
DCHECK_GE(delta.height, 0.0) << "Should NOT shrink in height";
if (localVerticalShift) {
NSPoint origin = [view frame].origin;
@@ -164,7 +134,7 @@ CGFloat AutoSizeGroup(NSArray* views, AutoSizeGroupBehavior behavior,
case kAutoSizeGroupBehaviorVerticalFirstToFit: {
// Just size the top one.
NSView* view = [views objectAtIndex:1];
- NSSize delta = WrapOrSizeToFit(view);
+ NSSize delta = cocoa_l10n_util::WrapOrSizeToFit(view);
DCHECK_GE(delta.height, 0.0) << "Should NOT shrink in height";
localVerticalShift += delta.height;
break;
@@ -176,7 +146,7 @@ CGFloat AutoSizeGroup(NSArray* views, AutoSizeGroupBehavior behavior,
NSUInteger count = [views count];
for (NSUInteger index = 1; index < count; ++index) {
NSView* view = [views objectAtIndex:index];
- NSSize delta = WrapOrSizeToFit(view);
+ NSSize delta = cocoa_l10n_util::WrapOrSizeToFit(view);
DCHECK_GE(delta.height, 0.0) << "Should NOT shrink in height";
if (horizontalShift) {
NSPoint origin = [view frame].origin;
@@ -194,7 +164,7 @@ CGFloat AutoSizeGroup(NSArray* views, AutoSizeGroupBehavior behavior,
CGFloat horizontalShift = 0.0;
for (NSUInteger index = [views count] - 1; index > 1; --index) {
NSView* view = [views objectAtIndex:index];
- NSSize delta = WrapOrSizeToFit(view);
+ NSSize delta = cocoa_l10n_util::WrapOrSizeToFit(view);
DCHECK_GE(delta.height, 0.0) << "Should NOT shrink in height";
horizontalShift -= delta.width;
NSPoint origin = [view frame].origin;
@@ -243,25 +213,13 @@ CGFloat AutoSizeGroup(NSArray* views, AutoSizeGroupBehavior behavior,
return localVerticalShift + nonLabelShift;
}
-// Compare function for -[NSArray sortedArrayUsingFunction:context:] that
-// sorts the views in Y order bottom up.
-NSInteger CompareFrameY(id view1, id view2, void* context) {
- CGFloat y1 = NSMinY([view1 frame]);
- CGFloat y2 = NSMinY([view2 frame]);
- if (y1 < y2)
- return NSOrderedAscending;
- else if (y1 > y2)
- return NSOrderedDescending;
- else
- return NSOrderedSame;
-}
-
// Helper to remove a view and move everything above it down to take over the
// space.
void RemoveViewFromView(NSView* view, NSView* toRemove) {
// Sort bottom up so we can spin over what is above it.
NSArray* views =
- [[view subviews] sortedArrayUsingFunction:CompareFrameY context:NULL];
+ [[view subviews] sortedArrayUsingFunction:cocoa_l10n_util::CompareFrameY
+ context:NULL];
// Find where |toRemove| was.
NSUInteger index = [views indexOfObject:toRemove];
@@ -322,9 +280,10 @@ CGFloat AutoSizeUnderTheHoodContent(NSView* view,
// Loop bottom up through the views sizing and shifting.
NSArray* views =
- [[view subviews] sortedArrayUsingFunction:CompareFrameY context:NULL];
+ [[view subviews] sortedArrayUsingFunction:cocoa_l10n_util::CompareFrameY
+ context:NULL];
for (NSView* view in views) {
- NSSize delta = WrapOrSizeToFit(view);
+ NSSize delta = cocoa_l10n_util::WrapOrSizeToFit(view);
DCHECK_GE(delta.height, 0.0) << "Should NOT shrink in height";
if (verticalShift) {
NSPoint origin = [view frame].origin;