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

Unified Diff: chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.mm

Issue 2825048: [Mac] Allow omnibox decorations to decline mouse events. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: Rohit's comment comment, and merge with content-setting change. Created 10 years, 5 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.mm
diff --git a/chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.mm b/chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.mm
index 3d62be62bffe8da6dd96f6ef57ca06eab5774a3a..4e464567956232debcf75dd0e71d43bf447cc7d3 100644
--- a/chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.mm
+++ b/chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.mm
@@ -167,7 +167,9 @@ void CalculatePositionsHelper(
// |decorations| will contain the resulting visible decorations, and
// |decoration_frames| will contain their frames in the same
// coordinates as |frame|. Decorations will be ordered left to right.
-void CalculatePositionsInFrame(
+// As a convenience returns the index of the first right-hand
+// decoration.
+size_t CalculatePositionsInFrame(
NSRect frame,
const std::vector<LocationBarDecoration*>& left_decorations,
const std::vector<LocationBarDecoration*>& right_decorations,
@@ -199,6 +201,7 @@ void CalculatePositionsInFrame(
decoration_frames->end());
*remaining_frame = frame;
+ return left_count;
}
} // namespace
@@ -386,6 +389,46 @@ void CalculatePositionsInFrame(
return textFrame;
}
+- (NSRect)textCursorFrameForFrame:(NSRect)cellFrame {
+ std::vector<LocationBarDecoration*> decorations;
+ std::vector<NSRect> decorationFrames;
+ NSRect textFrame;
+ size_t left_count =
+ CalculatePositionsInFrame(cellFrame, leftDecorations_, rightDecorations_,
+ &decorations, &decorationFrames, &textFrame);
+
+ // Determine the left-most extent for the i-beam cursor.
+ CGFloat minX = NSMinX(textFrame);
+ for (size_t index = left_count; index--; ) {
+ if (decorations[index]->AcceptsMousePress())
+ break;
+
+ // If at leftmost decoration, expand to edge of cell.
+ if (!index) {
+ minX = NSMinX(cellFrame);
+ } else {
+ minX = NSMinX(decorationFrames[index]) - kDecorationHorizontalPad;
+ }
+ }
+
+ // Determine the right-most extent for the i-beam cursor.
+ CGFloat maxX = NSMaxX(textFrame);
+ for (size_t index = left_count; index < decorations.size(); ++index) {
+ if (decorations[index]->AcceptsMousePress())
+ break;
+
+ // If at rightmost decoration, expand to edge of cell.
+ if (index == decorations.size() - 1) {
+ maxX = NSMaxX(cellFrame);
+ } else {
+ maxX = NSMaxX(decorationFrames[index]) + kDecorationHorizontalPad;
+ }
+ }
+
+ // I-beam cursor covers left-most to right-most.
+ return NSMakeRect(minX, NSMinY(textFrame), maxX - minX, NSHeight(textFrame));
+}
+
- (void)drawHintWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
DCHECK(hintString_);
@@ -466,7 +509,7 @@ void CalculatePositionsInFrame(
ofView:(AutocompleteTextField*)controlView {
LocationBarDecoration* decoration =
[self decorationForEvent:theEvent inRect:cellFrame ofView:controlView];
- if (!decoration)
+ if (!decoration || !decoration->AcceptsMousePress())
return NO;
NSRect decorationRect =

Powered by Google App Engine
This is Rietveld 408576698