Commit 78150c3c authored by shess@chromium.org's avatar shess@chromium.org

[Mac] Re-enable decoration tooltips in omnibox.

AutocompleteTextField clears state, then asks
AutocompleteTextFieldCell to regenerate the tooltips.

BUG=49321
TEST=tooltips for star, content settings, page actions.
TEST= AutocompleteTextFieldCellTest.UpdateToolTips

Review URL: http://codereview.chromium.org/2868058

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52940 0039d316-1c4b-4281-b951-d872f2087c98
parent 2c2b01d0
......@@ -128,6 +128,10 @@ class AutocompleteTextFieldObserver {
// Return the appropriate menu for any decoration under |event|.
- (NSMenu*)decorationMenuForEvent:(NSEvent*)event;
// Retains |tooltip| (in |currentToolTips_|) and adds this tooltip
// via -[NSView addToolTipRect:owner:userData:].
- (void)addToolTip:(NSString*)tooltip forRect:(NSRect)aRect;
@end
#endif // CHROME_BROWSER_COCOA_AUTOCOMPLETE_TEXT_FIELD_H_
......@@ -204,6 +204,11 @@
[undoManager_ removeAllActions];
}
- (void)addToolTip:(NSString*)tooltip forRect:(NSRect)aRect {
[currentToolTips_ addObject:tooltip];
[self addToolTipRect:aRect owner:tooltip userData:nil];
}
// TODO(shess): -resetFieldEditorFrameIfNeeded is the place where
// changes to the cell layout should be flushed. LocationBarViewMac
// and ToolbarController are calling this routine directly, and I
......@@ -218,25 +223,10 @@
// subviews. Unless more tooltips are added to this view, this should suffice
// in place of managing a set of NSToolTipTag objects.
[self removeAllToolTips];
[currentToolTips_ removeAllObjects];
#if 0
// TODO(shess): Bring back tooltips. All the wiring is in there,
// just need to hook it up.
// http://crbug.com/49321
AutocompleteTextFieldCell* cell = [self cell];
for (AutocompleteTextFieldIcon* icon in [cell layedOutIcons:[self bounds]]) {
NSRect iconRect = [icon rect];
NSString* tooltip = [icon view]->GetToolTip();
if (!tooltip)
continue;
// -[NSView addToolTipRect:owner:userData] does _not_ retain its |owner:|.
// Put the string in a collection so it can't be dealloced while in use.
[currentToolTips_ addObject:tooltip];
[self addToolTipRect:iconRect owner:tooltip userData:nil];
}
#endif
// Reload the decoration tooltips.
[currentToolTips_ removeAllObjects];
[[self cell] updateToolTipsInRect:[self bounds] ofView:self];
}
// NOTE(shess): http://crbug.com/19116 describes a weird bug which
......
......@@ -68,4 +68,9 @@ class LocationBarDecoration;
// Keyword-search bubble, for instance.
- (NSRect)textCursorFrameForFrame:(NSRect)cellFrame;
// Setup decoration tooltips on |controlView| by calling
// |-addToolTip:forRect:|.
- (void)updateToolTipsInRect:(NSRect)cellFrame
ofView:(AutocompleteTextField*)controlView;
@end
......@@ -366,4 +366,19 @@ size_t CalculatePositionsInFrame(
return NSDragOperationCopy;
}
- (void)updateToolTipsInRect:(NSRect)cellFrame
ofView:(AutocompleteTextField*)controlView {
std::vector<LocationBarDecoration*> decorations;
std::vector<NSRect> decorationFrames;
NSRect textFrame;
CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_,
&decorations, &decorationFrames, &textFrame);
for (size_t i = 0; i < decorations.size(); ++i) {
NSString* tooltip = decorations[i]->GetToolTip();
if ([tooltip length] > 0)
[controlView addToolTip:tooltip forRect:decorationFrames[i]];
}
}
@end
......@@ -18,7 +18,9 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#import "third_party/ocmock/OCMock/OCMock.h"
using ::testing::Return;
using ::testing::StrictMock;
using ::testing::_;
......@@ -36,6 +38,7 @@ class MockDecoration : public LocationBarDecoration {
virtual CGFloat GetWidthForSpace(CGFloat width) { return 20.0; }
MOCK_METHOD2(DrawInFrame, void(NSRect frame, NSView* control_view));
MOCK_METHOD0(GetToolTip, NSString*());
};
class AutocompleteTextFieldCellTest : public CocoaTest {
......@@ -260,4 +263,37 @@ TEST_F(AutocompleteTextFieldCellTest, RightDecorationFrame) {
EXPECT_LT(NSMinX(textFrame), NSMinX(decoration1Rect));
}
// Verify -[AutocompleteTextFieldCell updateToolTipsInRect:ofView:].
TEST_F(AutocompleteTextFieldCellTest, UpdateToolTips) {
NSString* tooltip = @"tooltip";
// Left decoration returns a tooltip, make sure it is called at
// least once.
mock_left_decoration_.SetVisible(true);
EXPECT_CALL(mock_left_decoration_, GetToolTip())
.WillOnce(Return(tooltip))
.WillRepeatedly(Return(tooltip));
// Right decoration returns no tooltip, make sure it is called at
// least once.
mock_right_decoration0_.SetVisible(true);
EXPECT_CALL(mock_right_decoration0_, GetToolTip())
.WillOnce(Return((NSString*)nil))
.WillRepeatedly(Return((NSString*)nil));
AutocompleteTextFieldCell* cell =
static_cast<AutocompleteTextFieldCell*>([view_ cell]);
const NSRect bounds = [view_ bounds];
const NSRect leftDecorationRect =
[cell frameForDecoration:&mock_left_decoration_ inFrame:bounds];
// |controlView| gets the tooltip for the left decoration.
id controlView = [OCMockObject mockForClass:[AutocompleteTextField class]];
[[controlView expect] addToolTip:tooltip forRect:leftDecorationRect];
[cell updateToolTipsInRect:bounds ofView:controlView];
[controlView verify];
}
} // namespace
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