| OLD | NEW |
| 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 #import "chrome/browser/ui/cocoa/intents/web_intent_message_view_controller.h" | 5 #import "chrome/browser/ui/cocoa/intents/web_intent_message_view_controller.h" |
| 6 | 6 |
| 7 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_control_u
tils.h" | 7 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_control_u
tils.h" |
| 8 #import "chrome/browser/ui/cocoa/flipped_view.h" | 8 #import "chrome/browser/ui/cocoa/flipped_view.h" |
| 9 #import "chrome/browser/ui/constrained_window.h" | 9 #import "chrome/browser/ui/constrained_window.h" |
| 10 #import "chrome/browser/ui/constrained_window_constants.h" |
| 10 #include "chrome/browser/ui/intents/web_intent_picker.h" | 11 #include "chrome/browser/ui/intents/web_intent_picker.h" |
| 11 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 12 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| 12 | 13 |
| 13 @interface WebIntentMessageViewController () | 14 @interface WebIntentMessageViewController () |
| 14 // Resize the title and message text field to fit the given width. | 15 // Resize the title and message text field to fit the given width. |
| 15 - (void)resizeTextFieldsToWidth:(CGFloat)width; | 16 - (void)resizeTextFieldsToWidth:(CGFloat)width; |
| 16 @end | 17 @end |
| 17 | 18 |
| 18 @implementation WebIntentMessageViewController | 19 @implementation WebIntentMessageViewController |
| 19 | 20 |
| 20 - (id)init { | 21 - (id)init { |
| 21 if ((self = [super init])) { | 22 if ((self = [super init])) { |
| 22 scoped_nsobject<NSView> view( | 23 scoped_nsobject<NSView> view( |
| 23 [[FlippedView alloc] initWithFrame:NSZeroRect]); | 24 [[FlippedView alloc] initWithFrame:NSZeroRect]); |
| 24 [self setView:view]; | 25 [self setView:view]; |
| 25 | 26 |
| 26 titleTextField_.reset([constrained_window::CreateLabel() retain]); | 27 titleTextField_.reset([constrained_window::CreateLabel() retain]); |
| 27 [[self view] addSubview:titleTextField_]; | 28 [[self view] addSubview:titleTextField_]; |
| 28 messageTextField_.reset([constrained_window::CreateLabel() retain]); | 29 messageTextField_.reset([constrained_window::CreateLabel() retain]); |
| 29 [[self view] addSubview:messageTextField_]; | 30 [[self view] addSubview:messageTextField_]; |
| 30 } | 31 } |
| 31 return self; | 32 return self; |
| 32 } | 33 } |
| 33 | 34 |
| 34 - (void)setTitle:(NSString*)title { | 35 - (void)setTitle:(NSString*)title { |
| 35 [titleTextField_ setAttributedStringValue: | 36 [titleTextField_ setAttributedStringValue: |
| 36 constrained_window::GetAttributedLabelString( | 37 constrained_window::GetAttributedLabelString( |
| 37 title, | 38 title, |
| 38 ConstrainedWindow::kTitleFontStyle, | 39 ConstrainedWindowConstants::kTitleFontStyle, |
| 39 NSNaturalTextAlignment, | 40 NSNaturalTextAlignment, |
| 40 NSLineBreakByWordWrapping)]; | 41 NSLineBreakByWordWrapping)]; |
| 41 } | 42 } |
| 42 | 43 |
| 43 - (void)setMessage:(NSString*)message { | 44 - (void)setMessage:(NSString*)message { |
| 44 [messageTextField_ setAttributedStringValue: | 45 [messageTextField_ setAttributedStringValue: |
| 45 constrained_window::GetAttributedLabelString( | 46 constrained_window::GetAttributedLabelString( |
| 46 message, | 47 message, |
| 47 ConstrainedWindow::kTextFontStyle, | 48 ConstrainedWindowConstants::kTextFontStyle, |
| 48 NSNaturalTextAlignment, | 49 NSNaturalTextAlignment, |
| 49 NSLineBreakByWordWrapping)]; | 50 NSLineBreakByWordWrapping)]; |
| 50 } | 51 } |
| 51 | 52 |
| 52 - (NSSize)minimumSizeForInnerWidth:(CGFloat)innerWidth { | 53 - (NSSize)minimumSizeForInnerWidth:(CGFloat)innerWidth { |
| 53 [self resizeTextFieldsToWidth:innerWidth]; | 54 [self resizeTextFieldsToWidth:innerWidth]; |
| 54 CGFloat height = NSHeight([titleTextField_ frame]); | 55 CGFloat height = NSHeight([titleTextField_ frame]); |
| 55 height += NSHeight([messageTextField_ frame]); | 56 height += NSHeight([messageTextField_ frame]); |
| 56 height += ConstrainedWindow::kRowPadding; | 57 height += ConstrainedWindowConstants::kRowPadding; |
| 57 return NSMakeSize(innerWidth, height); | 58 return NSMakeSize(innerWidth, height); |
| 58 } | 59 } |
| 59 | 60 |
| 60 - (void)layoutSubviewsWithinFrame:(NSRect)innerFrame { | 61 - (void)layoutSubviewsWithinFrame:(NSRect)innerFrame { |
| 61 [self resizeTextFieldsToWidth:NSWidth(innerFrame)]; | 62 [self resizeTextFieldsToWidth:NSWidth(innerFrame)]; |
| 62 | 63 |
| 63 NSRect titleFrame = [titleTextField_ frame]; | 64 NSRect titleFrame = [titleTextField_ frame]; |
| 64 titleFrame.origin = innerFrame.origin; | 65 titleFrame.origin = innerFrame.origin; |
| 65 [titleTextField_ setFrame:titleFrame]; | 66 [titleTextField_ setFrame:titleFrame]; |
| 66 | 67 |
| 67 NSRect messageFrame = [messageTextField_ frame]; | 68 NSRect messageFrame = [messageTextField_ frame]; |
| 68 messageFrame.origin.x = NSMinX(innerFrame); | 69 messageFrame.origin.x = NSMinX(innerFrame); |
| 69 messageFrame.origin.y = NSMaxY(titleFrame) + ConstrainedWindow::kRowPadding; | 70 messageFrame.origin.y = NSMaxY(titleFrame) + |
| 71 ConstrainedWindowConstants::kRowPadding; |
| 70 [messageTextField_ setFrame:messageFrame]; | 72 [messageTextField_ setFrame:messageFrame]; |
| 71 } | 73 } |
| 72 | 74 |
| 73 - (void)resizeTextFieldsToWidth:(CGFloat)width { | 75 - (void)resizeTextFieldsToWidth:(CGFloat)width { |
| 74 NSRect frame = NSZeroRect; | 76 NSRect frame = NSZeroRect; |
| 75 | 77 |
| 76 frame.size.width = width; | 78 frame.size.width = width; |
| 77 [messageTextField_ setFrame:frame]; | 79 [messageTextField_ setFrame:frame]; |
| 78 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField: | 80 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField: |
| 79 messageTextField_]; | 81 messageTextField_]; |
| 80 | 82 |
| 81 frame.size.width -= ConstrainedWindow::GetCloseButtonSize() + | 83 frame.size.width -= ConstrainedWindow::GetCloseButtonSize() + |
| 82 WebIntentPicker::kIconTextPadding; | 84 WebIntentPicker::kIconTextPadding; |
| 83 [titleTextField_ setFrame:frame]; | 85 [titleTextField_ setFrame:frame]; |
| 84 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleTextField_]; | 86 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleTextField_]; |
| 85 } | 87 } |
| 86 | 88 |
| 87 @end | 89 @end |
| OLD | NEW |