OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 } | 169 } |
170 | 170 |
171 return colors[state][kind]; | 171 return colors[state][kind]; |
172 } | 172 } |
173 | 173 |
174 void AutocompleteResultView::SetMatch(const AutocompleteMatch& match) { | 174 void AutocompleteResultView::SetMatch(const AutocompleteMatch& match) { |
175 match_ = match; | 175 match_ = match; |
176 Layout(); | 176 Layout(); |
177 } | 177 } |
178 | 178 |
| 179 |
| 180 gfx::Size AutocompleteResultView::GetCollapsedSize() { |
| 181 return gfx::Size(icon_bounds_.right() + LocationBarView::kItemPadding + |
| 182 ellipsis_width_ + LocationBarView::kItemPadding, height()); |
| 183 } |
| 184 |
| 185 gfx::Size AutocompleteResultView::GetPreferredSize() { |
| 186 return gfx::Size(0, std::max( |
| 187 default_icon_size_ + (kMinimumIconVerticalPadding * 2), |
| 188 GetTextHeight() + (kMinimumTextVerticalPadding * 2))); |
| 189 } |
| 190 |
179 //////////////////////////////////////////////////////////////////////////////// | 191 //////////////////////////////////////////////////////////////////////////////// |
180 // AutocompleteResultView, protected: | 192 // AutocompleteResultView, protected: |
181 | 193 |
182 void AutocompleteResultView::PaintMatch(gfx::Canvas* canvas, | 194 void AutocompleteResultView::PaintMatch(gfx::Canvas* canvas, |
183 const AutocompleteMatch& match, | 195 const AutocompleteMatch& match, |
184 int x) { | 196 int x) { |
185 x = DrawString(canvas, match.contents, match.contents_class, false, x, | 197 x = DrawString(canvas, match.contents, match.contents_class, false, x, |
186 text_bounds_.y()); | 198 text_bounds_.y()); |
187 | 199 |
188 // Paint the description. | 200 // Paint the description. |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 // ellipsis we'll append to it, or | 498 // ellipsis we'll append to it, or |
487 // * It is also bold, in which case we don't want to fall back | 499 // * It is also bold, in which case we don't want to fall back |
488 // to a normal ellipsis anyway (see comment above). | 500 // to a normal ellipsis anyway (see comment above). |
489 } | 501 } |
490 } | 502 } |
491 | 503 |
492 // We couldn't draw anything. | 504 // We couldn't draw anything. |
493 runs->clear(); | 505 runs->clear(); |
494 } | 506 } |
495 | 507 |
496 gfx::Size AutocompleteResultView::GetPreferredSize() { | |
497 return gfx::Size(0, std::max( | |
498 default_icon_size_ + (kMinimumIconVerticalPadding * 2), | |
499 GetTextHeight() + (kMinimumTextVerticalPadding * 2))); | |
500 } | |
501 | |
502 void AutocompleteResultView::Layout() { | 508 void AutocompleteResultView::Layout() { |
503 const SkBitmap* icon = GetIcon(); | 509 const SkBitmap* icon = GetIcon(); |
504 icon_bounds_.SetRect(LocationBarView::kEdgeItemPadding + | 510 icon_bounds_.SetRect(LocationBarView::kEdgeItemPadding + |
505 ((icon->width() == default_icon_size_) ? | 511 ((icon->width() == default_icon_size_) ? |
506 0 : LocationBarView::kIconInternalPadding), | 512 0 : LocationBarView::kIconInternalPadding), |
507 (height() - icon->height()) / 2, icon->width(), icon->height()); | 513 (height() - icon->height()) / 2, icon->width(), icon->height()); |
508 | 514 |
509 int text_x = LocationBarView::kEdgeItemPadding + default_icon_size_ + | 515 int text_x = LocationBarView::kEdgeItemPadding + default_icon_size_ + |
510 LocationBarView::kItemPadding; | 516 LocationBarView::kItemPadding; |
511 int text_height = GetTextHeight(); | 517 int text_height = GetTextHeight(); |
512 text_bounds_.SetRect(text_x, std::max(0, (height() - text_height) / 2), | 518 text_bounds_.SetRect(text_x, std::max(0, (height() - text_height) / 2), |
513 std::max(bounds().width() - text_x - LocationBarView::kEdgeItemPadding, | 519 std::max(bounds().width() - text_x - LocationBarView::kEdgeItemPadding, |
514 0), text_height); | 520 0), text_height); |
515 } | 521 } |
516 | 522 |
517 void AutocompleteResultView::OnPaint(gfx::Canvas* canvas) { | 523 void AutocompleteResultView::OnPaint(gfx::Canvas* canvas) { |
518 const ResultViewState state = GetState(); | 524 const ResultViewState state = GetState(); |
519 if (state != NORMAL) | 525 if (state != NORMAL) |
520 canvas->AsCanvasSkia()->drawColor(GetColor(state, BACKGROUND)); | 526 canvas->AsCanvasSkia()->drawColor(GetColor(state, BACKGROUND)); |
521 | 527 |
522 // Paint the icon. | 528 // Paint the icon. |
523 canvas->DrawBitmapInt(*GetIcon(), GetMirroredXForRect(icon_bounds_), | 529 canvas->DrawBitmapInt(*GetIcon(), GetMirroredXForRect(icon_bounds_), |
524 icon_bounds_.y()); | 530 icon_bounds_.y()); |
525 | 531 |
526 // Paint the text. | 532 // Paint the text. |
527 int x = GetMirroredXForRect(text_bounds_); | 533 int x = GetMirroredXForRect(text_bounds_); |
528 mirroring_context_->Initialize(x, text_bounds_.width()); | 534 mirroring_context_->Initialize(x, text_bounds_.width()); |
529 PaintMatch(canvas, match_, x); | 535 PaintMatch(canvas, match_, x); |
530 } | 536 } |
| 537 |
OLD | NEW |