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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_result_view.cc

Issue 1000163005: [AiS] using const for vertical padding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_result_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // For WinDDK ATL compatibility, these ATL headers must come first. 5 // For WinDDK ATL compatibility, these ATL headers must come first.
6 #include "build/build_config.h" 6 #include "build/build_config.h"
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <atlbase.h> // NOLINT 8 #include <atlbase.h> // NOLINT
9 #include <atlwin.h> // NOLINT 9 #include <atlwin.h> // NOLINT
10 #endif 10 #endif
(...skipping 22 matching lines...) Expand all
33 #include "ui/gfx/image/image.h" 33 #include "ui/gfx/image/image.h"
34 #include "ui/gfx/range/range.h" 34 #include "ui/gfx/range/range.h"
35 #include "ui/gfx/render_text.h" 35 #include "ui/gfx/render_text.h"
36 #include "ui/gfx/text_utils.h" 36 #include "ui/gfx/text_utils.h"
37 #include "ui/native_theme/native_theme.h" 37 #include "ui/native_theme/native_theme.h"
38 38
39 using ui::NativeTheme; 39 using ui::NativeTheme;
40 40
41 namespace { 41 namespace {
42 42
43 // The minimum distance between the top and bottom of the icon and the
44 // top or bottom of the row.
45 const int kMinimumIconVerticalPadding = 2;
46
43 // Calls back to the OmniboxResultView when the requested image is downloaded. 47 // Calls back to the OmniboxResultView when the requested image is downloaded.
44 // This is a separate class instead of being implemented on OmniboxResultView 48 // This is a separate class instead of being implemented on OmniboxResultView
45 // because BitmapFetcherService currently takes ownership of this object. 49 // because BitmapFetcherService currently takes ownership of this object.
46 // TODO(dschuyler): Make BitmapFetcherService use the more typical non-owning 50 // TODO(dschuyler): Make BitmapFetcherService use the more typical non-owning
47 // ObserverList pattern and have OmniboxResultView implement the Observer call 51 // ObserverList pattern and have OmniboxResultView implement the Observer call
48 // directly. 52 // directly.
49 class AnswerImageObserver : public BitmapFetcherService::Observer { 53 class AnswerImageObserver : public BitmapFetcherService::Observer {
50 public: 54 public:
51 explicit AnswerImageObserver( 55 explicit AnswerImageObserver(
52 const base::WeakPtr<OmniboxResultView>& view) 56 const base::WeakPtr<OmniboxResultView>& view)
53 : view_(view) {} 57 : view_(view) {}
54 58
55 void OnImageChanged(BitmapFetcherService::RequestId request_id, 59 void OnImageChanged(BitmapFetcherService::RequestId request_id,
56 const SkBitmap& image) override; 60 const SkBitmap& image) override;
57 61
58 private: 62 private:
59 const base::WeakPtr<OmniboxResultView> view_; 63 const base::WeakPtr<OmniboxResultView> view_;
60 DISALLOW_COPY_AND_ASSIGN(AnswerImageObserver); 64 DISALLOW_COPY_AND_ASSIGN(AnswerImageObserver);
61 }; 65 };
62 66
63 void AnswerImageObserver::OnImageChanged( 67 void AnswerImageObserver::OnImageChanged(
64 BitmapFetcherService::RequestId request_id, 68 BitmapFetcherService::RequestId request_id,
65 const SkBitmap& image) { 69 const SkBitmap& image) {
66 DCHECK(!image.empty()); 70 DCHECK(!image.empty());
67 if (view_) 71 if (view_)
68 view_->SetAnswerImage(gfx::ImageSkia::CreateFrom1xBitmap(image)); 72 view_->SetAnswerImage(gfx::ImageSkia::CreateFrom1xBitmap(image));
69 } 73 }
70 74
71 // The minimum distance between the top and bottom of the {icon|text} and the
72 // top or bottom of the row.
73 const int kMinimumIconVerticalPadding = 2;
74 const int kMinimumTextVerticalPadding = 3;
75
76 // A mapping from OmniboxResultView's ResultViewState/ColorKind types to 75 // A mapping from OmniboxResultView's ResultViewState/ColorKind types to
77 // NativeTheme colors. 76 // NativeTheme colors.
78 struct TranslationTable { 77 struct TranslationTable {
79 ui::NativeTheme::ColorId id; 78 ui::NativeTheme::ColorId id;
80 OmniboxResultView::ResultViewState state; 79 OmniboxResultView::ResultViewState state;
81 OmniboxResultView::ColorKind kind; 80 OmniboxResultView::ColorKind kind;
82 } static const kTranslationTable[] = { 81 } static const kTranslationTable[] = {
83 { NativeTheme::kColorId_ResultsTableNormalBackground, 82 { NativeTheme::kColorId_ResultsTableNormalBackground,
84 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND }, 83 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND },
85 { NativeTheme::kColorId_ResultsTableHoveredBackground, 84 { NativeTheme::kColorId_ResultsTableHoveredBackground,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 151
153 DISALLOW_COPY_AND_ASSIGN(MirroringContext); 152 DISALLOW_COPY_AND_ASSIGN(MirroringContext);
154 }; 153 };
155 154
156 OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model, 155 OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model,
157 int model_index, 156 int model_index,
158 LocationBarView* location_bar_view, 157 LocationBarView* location_bar_view,
159 const gfx::FontList& font_list) 158 const gfx::FontList& font_list)
160 : edge_item_padding_(LocationBarView::kItemPadding), 159 : edge_item_padding_(LocationBarView::kItemPadding),
161 item_padding_(LocationBarView::kItemPadding), 160 item_padding_(LocationBarView::kItemPadding),
162 minimum_text_vertical_padding_(kMinimumTextVerticalPadding),
163 model_(model), 161 model_(model),
164 model_index_(model_index), 162 model_index_(model_index),
165 location_bar_view_(location_bar_view), 163 location_bar_view_(location_bar_view),
166 image_service_(BitmapFetcherServiceFactory::GetForBrowserContext( 164 image_service_(BitmapFetcherServiceFactory::GetForBrowserContext(
167 location_bar_view_->profile())), 165 location_bar_view_->profile())),
168 font_list_(font_list), 166 font_list_(font_list),
169 font_height_( 167 font_height_(
170 std::max(font_list.GetHeight(), 168 std::max(font_list.GetHeight(),
171 font_list.DeriveWithStyle(gfx::Font::BOLD).GetHeight())), 169 font_list.DeriveWithStyle(gfx::Font::BOLD).GetHeight())),
172 mirroring_context_(new MirroringContext()), 170 mirroring_context_(new MirroringContext()),
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 // While the text in the RenderTexts may not have changed, the styling 243 // While the text in the RenderTexts may not have changed, the styling
246 // (color/bold) may need to change. So we reset them to cause them to be 244 // (color/bold) may need to change. So we reset them to cause them to be
247 // recomputed in OnPaint(). 245 // recomputed in OnPaint().
248 ResetRenderTexts(); 246 ResetRenderTexts();
249 SchedulePaint(); 247 SchedulePaint();
250 } 248 }
251 249
252 gfx::Size OmniboxResultView::GetPreferredSize() const { 250 gfx::Size OmniboxResultView::GetPreferredSize() const {
253 return gfx::Size(0, std::max( 251 return gfx::Size(0, std::max(
254 default_icon_size_ + (kMinimumIconVerticalPadding * 2), 252 default_icon_size_ + (kMinimumIconVerticalPadding * 2),
255 GetTextHeight() + (minimum_text_vertical_padding_ * 2))); 253 GetTextHeight() + (kMinimumTextVerticalPadding * 2)));
256 } 254 }
257 255
258 //////////////////////////////////////////////////////////////////////////////// 256 ////////////////////////////////////////////////////////////////////////////////
259 // OmniboxResultView, protected: 257 // OmniboxResultView, protected:
260 258
261 OmniboxResultView::ResultViewState OmniboxResultView::GetState() const { 259 OmniboxResultView::ResultViewState OmniboxResultView::GetState() const {
262 if (model_->IsSelectedIndex(model_index_)) 260 if (model_->IsSelectedIndex(model_index_))
263 return SELECTED; 261 return SELECTED;
264 return model_->IsHoveredIndex(model_index_) ? HOVERED : NORMAL; 262 return model_->IsHoveredIndex(model_index_) ? HOVERED : NORMAL;
265 } 263 }
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 } 631 }
634 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(), 632 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(),
635 keyword_description_rendertext_.get(), canvas, x); 633 keyword_description_rendertext_.get(), canvas, x);
636 } 634 }
637 } 635 }
638 636
639 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { 637 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) {
640 Layout(); 638 Layout();
641 SchedulePaint(); 639 SchedulePaint();
642 } 640 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_result_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698