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

Side by Side Diff: chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.mm

Issue 1099403005: [AiS] changing mac omnibox suggestions form NSMatrix to NSTableView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/omnibox/omnibox_popup_cell.h" 5 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_cell.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
11 #include "base/mac/scoped_nsobject.h" 11 #include "base/mac/scoped_nsobject.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/sys_string_conversions.h" 14 #include "base/strings/sys_string_conversions.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h" 16 #include "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h"
17 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" 17 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
18 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 18 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
19 #include "chrome/grit/generated_resources.h" 19 #include "chrome/grit/generated_resources.h"
20 #include "components/omnibox/suggestion_answer.h" 20 #include "components/omnibox/suggestion_answer.h"
21 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/gfx/font.h" 22 #include "ui/gfx/font.h"
23 23
24 namespace { 24 namespace {
25 25
26 // How much to adjust the cell sizing up from the default determined
27 // by the font.
28 const CGFloat kCellHeightAdjust = 6.0;
dschuyler 2015/04/24 18:43:08 This is moved from another file in this CL.
29
26 // How far to offset image column from the left. 30 // How far to offset image column from the left.
27 const CGFloat kImageXOffset = 5.0; 31 const CGFloat kImageXOffset = 5.0;
28 32
29 // How far to offset the text column from the left. 33 // How far to offset the text column from the left.
30 const CGFloat kTextStartOffset = 28.0; 34 const CGFloat kTextStartOffset = 28.0;
31 35
32 // Rounding radius of selection and hover background on popup items. 36 // Rounding radius of selection and hover background on popup items.
33 const CGFloat kCellRoundingRadius = 2.0; 37 const CGFloat kCellRoundingRadius = 2.0;
34 38
35 // Flips the given |rect| in context of the given |frame|. 39 // Flips the given |rect| in context of the given |frame|.
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 description_.reset([CreateClassifiedAttributedString( 202 description_.reset([CreateClassifiedAttributedString(
199 answerString, DimTextColor(), match_.description_class) retain]); 203 answerString, DimTextColor(), match_.description_class) retain]);
200 } else if (match_.description.empty()) { 204 } else if (match_.description.empty()) {
201 description_.reset(); 205 description_.reset();
202 } else { 206 } else {
203 description_.reset([CreateClassifiedAttributedString( 207 description_.reset([CreateClassifiedAttributedString(
204 match_.description, DimTextColor(), match_.description_class) retain]); 208 match_.description, DimTextColor(), match_.description_class) retain]);
205 } 209 }
206 } 210 }
207 211
212 - (id)copyWithZone:(NSZone*)zone {
213 NSAttributedString* separator = separator_.release();
groby-ooo-7-16 2015/04/24 20:11:16 Why release them?
dschuyler 2015/04/25 01:05:42 I was using code from this file as a pattern: src/
groby-ooo-7-16 2015/04/25 01:31:11 Huh? HyperlinkButtonCell's -copyWithZone: does not
214 NSAttributedString* description = description_.release();
215 NSAttributedString* prefix = prefix_.release();
dschuyler 2015/04/24 18:43:08 This is my first shot at a copyWithZone member. I
groby-ooo-7-16 2015/04/24 20:11:16 Why does this not work? Also, copy->separator_rese
dschuyler 2015/04/25 01:05:42 I must have mislead myself. I was getting a crash
groby-ooo-7-16 2015/04/25 01:31:11 I know it's tempting, but please don't cargo-cult
216 OmniboxPopupCell* copy = [super copyWithZone:zone];
217 copy->match_ = match_;
218 copy->separator_.reset([separator copy]);
219 separator_.reset(separator);
220 copy->description_.reset([description copy]);
221 description_.reset(description);
222 copy->prefix_.reset([prefix copy]);
223 prefix_.reset(prefix);
224 copy->maxMatchContentsWidth_ = maxMatchContentsWidth_;
225 copy->contentsOffset_ = contentsOffset_;
226 return copy;
227 }
228
229 - (NSRect)drawingRectForBounds:(NSRect)theRect {
230 // Enlarge the cell size.
231 theRect.size.height -= kCellHeightAdjust;
232 return theRect;
233 }
234
208 - (void)setMaxMatchContentsWidth:(CGFloat)maxMatchContentsWidth { 235 - (void)setMaxMatchContentsWidth:(CGFloat)maxMatchContentsWidth {
209 maxMatchContentsWidth_ = maxMatchContentsWidth; 236 maxMatchContentsWidth_ = maxMatchContentsWidth;
210 } 237 }
211 238
212 - (void)setContentsOffset:(CGFloat)contentsOffset { 239 - (void)setContentsOffset:(CGFloat)contentsOffset {
213 contentsOffset_ = contentsOffset; 240 contentsOffset_ = contentsOffset;
214 } 241 }
215 242
216 // The default NSButtonCell drawing leaves the image flush left and 243 // The default NSButtonCell drawing leaves the image flush left and
217 // the title next to the image. This spaces things out to line up 244 // the title next to the image. This spaces things out to line up
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 454 }
428 glyphOffset -= minOffset; 455 glyphOffset -= minOffset;
429 if (glyphWidth == 0) 456 if (glyphWidth == 0)
430 glyphWidth = inputWidth - glyphOffset; 457 glyphWidth = inputWidth - glyphOffset;
431 if (isContentsRTL) 458 if (isContentsRTL)
432 glyphOffset += glyphWidth; 459 glyphOffset += glyphWidth;
433 return isRTL ? (inputWidth - glyphOffset) : glyphOffset; 460 return isRTL ? (inputWidth - glyphOffset) : glyphOffset;
434 } 461 }
435 462
436 @end 463 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698