Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 int right_; | 96 int right_; |
| 97 | 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(MirroringContext); | 98 DISALLOW_COPY_AND_ASSIGN(MirroringContext); |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 AutocompleteResultView::AutocompleteResultView( | 101 AutocompleteResultView::AutocompleteResultView( |
| 102 AutocompleteResultViewModel* model, | 102 AutocompleteResultViewModel* model, |
| 103 int model_index, | 103 int model_index, |
| 104 const gfx::Font& font, | 104 const gfx::Font& font, |
| 105 const gfx::Font& bold_font) | 105 const gfx::Font& bold_font) |
| 106 : model_(model), | 106 : edge_item_padding_(LocationBarView::GetItemPadding()), |
| 107 item_padding_(LocationBarView::GetItemPadding()), | |
| 108 minimum_text_vertical_padding_(kMinimumTextVerticalPadding), | |
| 109 model_(model), | |
| 107 model_index_(model_index), | 110 model_index_(model_index), |
| 108 normal_font_(font), | 111 normal_font_(font), |
| 109 bold_font_(bold_font), | 112 bold_font_(bold_font), |
| 110 ellipsis_width_(font.GetStringWidth(string16(kEllipsis))), | 113 ellipsis_width_(font.GetStringWidth(string16(kEllipsis))), |
| 111 mirroring_context_(new MirroringContext()), | 114 mirroring_context_(new MirroringContext()), |
| 112 keyword_icon_(new views::ImageView()), | 115 keyword_icon_(new views::ImageView()), |
| 113 ALLOW_THIS_IN_INITIALIZER_LIST( | 116 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 114 animation_(new ui::SlideAnimation(this))) { | 117 animation_(new ui::SlideAnimation(this))) { |
| 115 CHECK_GE(model_index, 0); | 118 CHECK_GE(model_index, 0); |
| 116 if (default_icon_size_ == 0) { | 119 if (default_icon_size_ == 0) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 colors[i][TEXT] = | 166 colors[i][TEXT] = |
| 164 color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xdd); | 167 color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xdd); |
| 165 colors[i][DIMMED_TEXT] = | 168 colors[i][DIMMED_TEXT] = |
| 166 color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xbb); | 169 color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xbb); |
| 167 #else | 170 #else |
| 168 colors[i][DIMMED_TEXT] = | 171 colors[i][DIMMED_TEXT] = |
| 169 color_utils::AlphaBlend(colors[i][TEXT], colors[i][BACKGROUND], 128); | 172 color_utils::AlphaBlend(colors[i][TEXT], colors[i][BACKGROUND], 128); |
| 170 colors[i][URL] = color_utils::GetReadableColor(SkColorSetRGB(0, 128, 0), | 173 colors[i][URL] = color_utils::GetReadableColor(SkColorSetRGB(0, 128, 0), |
| 171 colors[i][BACKGROUND]); | 174 colors[i][BACKGROUND]); |
| 172 #endif | 175 #endif |
| 176 | |
| 177 // When using non-default color schemes, the divider color may clash with | |
| 178 // the bubble border, which is currently "hard coded" in images as black | |
| 179 // with an 0x40 alpha channel. See http://crbug.com/127861 | |
| 180 colors[i][DIVIDER] = color_utils::AlphaBlend(colors[i][TEXT], | |
|
Peter Kasting
2012/05/11 23:01:41
Nit: How about just:
// TODO(joi): Programm
Jói
2012/05/14 18:29:45
Done.
| |
| 181 colors[i][BACKGROUND], | |
| 182 0x34); // 20% | |
| 173 } | 183 } |
| 174 initialized = true; | 184 initialized = true; |
| 175 } | 185 } |
| 176 | 186 |
| 177 return colors[state][kind]; | 187 return colors[state][kind]; |
| 178 } | 188 } |
| 179 | 189 |
| 180 void AutocompleteResultView::SetMatch(const AutocompleteMatch& match) { | 190 void AutocompleteResultView::SetMatch(const AutocompleteMatch& match) { |
| 181 match_ = match; | 191 match_ = match; |
| 182 animation_->Reset(); | 192 animation_->Reset(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 201 } | 211 } |
| 202 | 212 |
| 203 void AutocompleteResultView::Invalidate() { | 213 void AutocompleteResultView::Invalidate() { |
| 204 keyword_icon_->SetImage(GetKeywordIcon()); | 214 keyword_icon_->SetImage(GetKeywordIcon()); |
| 205 SchedulePaint(); | 215 SchedulePaint(); |
| 206 } | 216 } |
| 207 | 217 |
| 208 gfx::Size AutocompleteResultView::GetPreferredSize() { | 218 gfx::Size AutocompleteResultView::GetPreferredSize() { |
| 209 return gfx::Size(0, std::max( | 219 return gfx::Size(0, std::max( |
| 210 default_icon_size_ + (kMinimumIconVerticalPadding * 2), | 220 default_icon_size_ + (kMinimumIconVerticalPadding * 2), |
| 211 GetTextHeight() + (kMinimumTextVerticalPadding * 2))); | 221 GetTextHeight() + (minimum_text_vertical_padding_ * 2))); |
| 212 } | 222 } |
| 213 | 223 |
| 214 //////////////////////////////////////////////////////////////////////////////// | 224 //////////////////////////////////////////////////////////////////////////////// |
| 215 // AutocompleteResultView, protected: | 225 // AutocompleteResultView, protected: |
| 216 | 226 |
| 227 AutocompleteResultView::ResultViewState | |
| 228 AutocompleteResultView::GetState() const { | |
| 229 if (model_->IsSelectedIndex(model_index_)) | |
| 230 return SELECTED; | |
| 231 return model_->IsHoveredIndex(model_index_) ? HOVERED : NORMAL; | |
| 232 } | |
| 233 | |
| 217 void AutocompleteResultView::PaintMatch(gfx::Canvas* canvas, | 234 void AutocompleteResultView::PaintMatch(gfx::Canvas* canvas, |
| 218 const AutocompleteMatch& match, | 235 const AutocompleteMatch& match, |
| 219 int x) { | 236 int x) { |
| 220 x = DrawString(canvas, match.contents, match.contents_class, false, x, | 237 x = DrawString(canvas, match.contents, match.contents_class, false, x, |
| 221 text_bounds_.y()); | 238 text_bounds_.y()); |
| 222 | 239 |
| 223 // Paint the description. | 240 // Paint the description. |
| 224 // TODO(pkasting): Because we paint in multiple separate pieces, we can wind | 241 // TODO(pkasting): Because we paint in multiple separate pieces, we can wind |
| 225 // up with no space even for an ellipsis for one or both of these pieces. | 242 // up with no space even for an ellipsis for one or both of these pieces. |
| 226 // Instead, we should paint the entire match as a single long string. This | 243 // Instead, we should paint the entire match as a single long string. This |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 252 | 269 |
| 253 // static | 270 // static |
| 254 bool AutocompleteResultView::SortRunsVisually(const RunData& lhs, | 271 bool AutocompleteResultView::SortRunsVisually(const RunData& lhs, |
| 255 const RunData& rhs) { | 272 const RunData& rhs) { |
| 256 return lhs.visual_order < rhs.visual_order; | 273 return lhs.visual_order < rhs.visual_order; |
| 257 } | 274 } |
| 258 | 275 |
| 259 // static | 276 // static |
| 260 int AutocompleteResultView::default_icon_size_ = 0; | 277 int AutocompleteResultView::default_icon_size_ = 0; |
| 261 | 278 |
| 262 AutocompleteResultView::ResultViewState | |
| 263 AutocompleteResultView::GetState() const { | |
| 264 if (model_->IsSelectedIndex(model_index_)) | |
| 265 return SELECTED; | |
| 266 return model_->IsHoveredIndex(model_index_) ? HOVERED : NORMAL; | |
| 267 } | |
| 268 | |
| 269 const SkBitmap* AutocompleteResultView::GetIcon() const { | 279 const SkBitmap* AutocompleteResultView::GetIcon() const { |
| 270 const SkBitmap* bitmap = model_->GetIconIfExtensionMatch(model_index_); | 280 const SkBitmap* bitmap = model_->GetIconIfExtensionMatch(model_index_); |
| 271 if (bitmap) | 281 if (bitmap) |
| 272 return bitmap; | 282 return bitmap; |
| 273 | 283 |
| 274 int icon = match_.starred ? | 284 int icon = match_.starred ? |
| 275 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); | 285 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); |
| 276 if (GetState() == SELECTED) { | 286 if (GetState() == SELECTED) { |
| 277 switch (icon) { | 287 switch (icon) { |
| 278 case IDR_OMNIBOX_EXTENSION_APP: | 288 case IDR_OMNIBOX_EXTENSION_APP: |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 } | 541 } |
| 532 } | 542 } |
| 533 | 543 |
| 534 // We couldn't draw anything. | 544 // We couldn't draw anything. |
| 535 runs->clear(); | 545 runs->clear(); |
| 536 } | 546 } |
| 537 | 547 |
| 538 void AutocompleteResultView::Layout() { | 548 void AutocompleteResultView::Layout() { |
| 539 const SkBitmap* icon = GetIcon(); | 549 const SkBitmap* icon = GetIcon(); |
| 540 | 550 |
| 541 icon_bounds_.SetRect(LocationBarView::kEdgeItemPadding + | 551 int icon_padding = (icon->width() == default_icon_size_) ? |
|
Peter Kasting
2012/05/11 23:01:41
Nit: Frankly I was OK with how it was before, just
| |
| 542 ((icon->width() == default_icon_size_) ? | 552 0 : LocationBarView::kIconInternalPadding; |
| 543 0 : LocationBarView::kIconInternalPadding), | 553 icon_bounds_.SetRect(edge_item_padding_ + icon_padding, |
| 544 (height() - icon->height()) / 2, icon->width(), icon->height()); | 554 (height() - icon->height()) / 2, |
| 555 icon->width(), | |
| 556 icon->height()); | |
| 545 | 557 |
| 546 int text_x = LocationBarView::kEdgeItemPadding + default_icon_size_ + | 558 int text_x = edge_item_padding_ + default_icon_size_ + item_padding_; |
| 547 LocationBarView::kItemPadding; | |
| 548 int text_height = GetTextHeight(); | 559 int text_height = GetTextHeight(); |
| 549 int text_width; | 560 int text_width; |
| 550 | 561 |
| 551 if (match_.associated_keyword.get()) { | 562 if (match_.associated_keyword.get()) { |
| 552 const int kw_collapsed_size = keyword_icon_->width() + | 563 const int kw_collapsed_size = keyword_icon_->width() + |
|
Peter Kasting
2012/05/11 23:01:41
Nit: Wrap after '=' instead of '+'
Jói
2012/05/14 18:29:45
Done.
| |
| 553 LocationBarView::kEdgeItemPadding; | 564 edge_item_padding_; |
| 554 const int max_kw_x = width() - kw_collapsed_size; | 565 const int max_kw_x = width() - kw_collapsed_size; |
| 555 const int kw_x = animation_->CurrentValueBetween(max_kw_x, | 566 const int kw_x = animation_->CurrentValueBetween(max_kw_x, |
|
Peter Kasting
2012/05/11 23:01:41
Nit: Wrap after '=' instead of ','
Jói
2012/05/14 18:29:45
Done.
| |
| 556 LocationBarView::kEdgeItemPadding); | 567 edge_item_padding_); |
| 557 const int kw_text_x = kw_x + keyword_icon_->width() + | 568 const int kw_text_x = kw_x + keyword_icon_->width() + item_padding_; |
| 558 LocationBarView::kItemPadding; | |
| 559 | 569 |
| 560 text_width = kw_x - text_x - LocationBarView::kItemPadding; | 570 text_width = kw_x - text_x - item_padding_; |
| 561 keyword_text_bounds_.SetRect(kw_text_x, 0, std::max( | 571 keyword_text_bounds_.SetRect(kw_text_x, 0, std::max( |
|
Peter Kasting
2012/05/11 23:01:41
Nit: Wrap before "std::max(" instead of after
Jói
2012/05/14 18:29:45
Done.
| |
| 562 width() - kw_text_x - LocationBarView::kEdgeItemPadding, 0), | 572 width() - kw_text_x - edge_item_padding_, 0), |
| 563 text_height); | 573 text_height); |
| 564 keyword_icon_->SetPosition(gfx::Point(kw_x, | 574 keyword_icon_->SetPosition(gfx::Point(kw_x, |
| 565 (height() - keyword_icon_->height()) / 2)); | 575 (height() - keyword_icon_->height()) / 2)); |
| 566 } else { | 576 } else { |
| 567 text_width = width() - text_x - LocationBarView::kEdgeItemPadding; | 577 text_width = width() - text_x - edge_item_padding_; |
| 568 } | 578 } |
| 569 | 579 |
| 570 text_bounds_.SetRect(text_x, std::max(0, (height() - text_height) / 2), | 580 text_bounds_.SetRect(text_x, std::max(0, (height() - text_height) / 2), |
| 571 std::max(text_width, 0), text_height); | 581 std::max(text_width, 0), text_height); |
| 572 } | 582 } |
| 573 | 583 |
| 574 void AutocompleteResultView::OnBoundsChanged( | 584 void AutocompleteResultView::OnBoundsChanged( |
| 575 const gfx::Rect& previous_bounds) { | 585 const gfx::Rect& previous_bounds) { |
| 576 animation_->SetSlideDuration(width() / 4); | 586 animation_->SetSlideDuration(width() / 4); |
| 577 } | 587 } |
| 578 | 588 |
| 579 void AutocompleteResultView::OnPaint(gfx::Canvas* canvas) { | 589 void AutocompleteResultView::OnPaint(gfx::Canvas* canvas) { |
| 580 const ResultViewState state = GetState(); | 590 const ResultViewState state = GetState(); |
| 581 if (state != NORMAL) | 591 if (state != NORMAL) |
| 582 canvas->DrawColor(GetColor(state, BACKGROUND)); | 592 canvas->DrawColor(GetColor(state, BACKGROUND)); |
| 583 | 593 |
| 584 if (!match_.associated_keyword.get() || | 594 if (!match_.associated_keyword.get() || |
| 585 keyword_icon_->x() > icon_bounds_.right()) { | 595 keyword_icon_->x() > icon_bounds_.right()) { |
| 586 // Paint the icon. | 596 // Paint the icon. |
| 587 canvas->DrawBitmapInt(*GetIcon(), GetMirroredXForRect(icon_bounds_), | 597 canvas->DrawBitmapInt(*GetIcon(), GetMirroredXForRect(icon_bounds_), |
| 588 icon_bounds_.y()); | 598 icon_bounds_.y()); |
| 589 | 599 |
| 590 // Paint the text. | 600 // Paint the text. |
| 591 int x = GetMirroredXForRect(text_bounds_); | 601 int x = GetMirroredXForRect(text_bounds_); |
| 592 mirroring_context_->Initialize(x, text_bounds_.width()); | 602 mirroring_context_->Initialize(x, text_bounds_.width()); |
| 593 PaintMatch(canvas, match_, x); | 603 PaintMatch(canvas, match_, x); |
| 594 } | 604 } |
| 595 | 605 |
| 596 if (match_.associated_keyword.get()) { | 606 if (match_.associated_keyword.get()) { |
| 597 // Paint the keyword text. | 607 // Paint the keyword text. |
| 598 int x = GetMirroredXForRect(keyword_text_bounds_); | 608 int x = GetMirroredXForRect(keyword_text_bounds_); |
| 599 mirroring_context_->Initialize(x, keyword_text_bounds_.width()); | 609 mirroring_context_->Initialize(x, keyword_text_bounds_.width()); |
| 600 PaintMatch(canvas, *match_.associated_keyword.get(), x); | 610 PaintMatch(canvas, *match_.associated_keyword.get(), x); |
| 601 } | 611 } |
| 602 } | 612 } |
| 603 | 613 |
| 604 void AutocompleteResultView::AnimationProgressed( | 614 void AutocompleteResultView::AnimationProgressed( |
| 605 const ui::Animation* animation) { | 615 const ui::Animation* animation) { |
| 606 Layout(); | 616 Layout(); |
| 607 SchedulePaint(); | 617 SchedulePaint(); |
| 608 } | 618 } |
| 609 | 619 |
| OLD | NEW |