diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-20 21:53:00 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-20 21:53:00 +0000 |
commit | 778b17bf1570722645f6815277e504c12542ad14 (patch) | |
tree | 0645b8b1cc5d9841411f00b783ce78f8f10d5e01 /chrome/browser/views/autocomplete | |
parent | 1286292ab7b47880a257b5480736ea7bf19eace9 (diff) | |
download | chromium_src-778b17bf1570722645f6815277e504c12542ad14.zip chromium_src-778b17bf1570722645f6815277e504c12542ad14.tar.gz chromium_src-778b17bf1570722645f6815277e504c12542ad14.tar.bz2 |
First round of getting text into the omnibox2 popup. Looks ugly and has no bolding.
Review URL: http://codereview.chromium.org/89005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14060 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/autocomplete')
-rw-r--r-- | chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc | 84 | ||||
-rw-r--r-- | chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h | 9 |
2 files changed, 53 insertions, 40 deletions
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc index 15866a3..0a76d2b 100644 --- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc @@ -18,14 +18,15 @@ #include "grit/theme_resources.h" #include "skia/include/SkShader.h" -// The stroke color around the popup border. -static const SkColor kEdgeColor = SkColorSetRGB(183, 195, 219); +static const SkColor kTransparentColor = SkColorSetARGB(0, 0, 0, 0); static const int kPopupTransparency = 235; static const int kHoverRowAlpha = 0x40; class AutocompleteResultView : public views::View { public: - AutocompleteResultView(AutocompleteResultViewModel* model, int model_index); + AutocompleteResultView(AutocompleteResultViewModel* model, + int model_index, + const ChromeFont& font); virtual ~AutocompleteResultView(); // Overridden from views::View: @@ -46,9 +47,7 @@ class AutocompleteResultView : public views::View { void PaintAsMoreRow(ChromeCanvas* canvas); // Get colors for row backgrounds and text for different row states. - SkColor GetHighlightRowColor() const; - SkColor GetHighlightTextColor() const; - SkColor GetHoverRowColor() const; + SkColor GetBackgroundColor() const; SkColor GetTextColor() const; // This row's model and model index. @@ -58,26 +57,31 @@ class AutocompleteResultView : public views::View { // True if the mouse is over this row. bool hot_; + // The font used to derive fonts for rendering the text in this row. + ChromeFont font_; + DISALLOW_COPY_AND_ASSIGN(AutocompleteResultView); }; AutocompleteResultView::AutocompleteResultView( AutocompleteResultViewModel* model, - int model_index) + int model_index, + const ChromeFont& font) : model_(model), model_index_(model_index), - hot_(false) { + hot_(false), + font_(font) { } AutocompleteResultView::~AutocompleteResultView() { } void AutocompleteResultView::Paint(ChromeCanvas* canvas) { - // Paint the row background if any. - if (model_->IsSelectedIndex(model_index_)) - canvas->FillRectInt(GetHighlightRowColor(), 0, 0, width(), height()); - else if (hot_) - canvas->FillRectInt(GetHoverRowColor(), 0, 0, width(), height()); + canvas->FillRectInt(GetBackgroundColor(), 0, 0, width(), height()); + + const AutocompleteMatch& match = model_->GetMatchAtIndex(model_index_); + canvas->DrawStringInt(match.contents, font_, GetTextColor(), 0, 0, width(), + height()); } gfx::Size AutocompleteResultView::GetPreferredSize() { @@ -143,21 +147,20 @@ void AutocompleteResultView::PaintAsMoreRow(ChromeCanvas* canvas) { } -SkColor AutocompleteResultView::GetHighlightRowColor() const { - return color_utils::GetSysSkColor(COLOR_HIGHLIGHT); -} - -SkColor AutocompleteResultView::GetHighlightTextColor() const { - return color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT); -} - -SkColor AutocompleteResultView::GetHoverRowColor() const { - COLORREF color = GetSysColor(COLOR_HIGHLIGHT); - return SkColorSetARGB(kHoverRowAlpha, GetRValue(color), GetGValue(color), - GetBValue(color)); +SkColor AutocompleteResultView::GetBackgroundColor() const { + if (model_->IsSelectedIndex(model_index_)) + return color_utils::GetSysSkColor(COLOR_HIGHLIGHT); + if (hot_) { + COLORREF color = GetSysColor(COLOR_HIGHLIGHT); + return SkColorSetARGB(kHoverRowAlpha, GetRValue(color), GetGValue(color), + GetBValue(color)); + } + return kTransparentColor; } SkColor AutocompleteResultView::GetTextColor() const { + if (model_->IsSelectedIndex(model_index_)) + return color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT); return color_utils::GetSysSkColor(COLOR_WINDOWTEXT); } @@ -271,27 +274,30 @@ AutocompletePopupContentsView::AutocompletePopupContentsView( : popup_(new AutocompletePopupWin(this)), model_(new AutocompletePopupModel(this, edit_model, profile)), edit_view_(edit_view), - popup_positioner_(popup_positioner) { + popup_positioner_(popup_positioner), + edit_font_(font) { set_border(new PopupBorder); } void AutocompletePopupContentsView::SetAutocompleteResult( const AutocompleteResult& result) { RemoveAllChildViews(true); - for (size_t i = 0; i < result.size(); ++i) { - AutocompleteMatch match = result.match_at(i); - AutocompleteResultView* result = new AutocompleteResultView(this, i); - AddChildView(result); - } - Layout(); + for (size_t i = 0; i < result.size(); ++i) + AddChildView(new AutocompleteResultView(this, i, edit_font_)); + // Update the popup's size by calling Show. This will cause us to be laid out + // again at the new size. + popup_->Show(); } gfx::Rect AutocompletePopupContentsView::GetPopupBounds() const { gfx::Insets insets; border()->GetInsets(&insets); gfx::Rect contents_bounds = popup_positioner_->GetPopupBounds(); - contents_bounds.set_height(100); // TODO(beng): size to contents (once we - // have contents!) + int child_count = GetChildViewCount(); + int height = 0; + for (int i = 0; i < child_count; ++i) + height += GetChildViewAt(i)->GetPreferredSize().height(); + contents_bounds.set_height(height); contents_bounds.Inset(-insets.left(), -insets.top(), -insets.right(), -insets.bottom()); return contents_bounds; @@ -343,9 +349,9 @@ bool AutocompletePopupContentsView::IsSelectedIndex(size_t index) { return index == model_->selected_line(); } -AutocompleteMatch::Type AutocompletePopupContentsView::GetResultTypeAtIndex( +const AutocompleteMatch& AutocompletePopupContentsView::GetMatchAtIndex( size_t index) { - return model_->result().match_at(index).type; + return model_->result().match_at(index); } void AutocompletePopupContentsView::OpenIndex( @@ -390,10 +396,12 @@ void AutocompletePopupContentsView::PaintChildren(ChromeCanvas* canvas) { true); contents_canvas.FillRectInt(color_utils::GetSysSkColor(COLOR_WINDOW), 0, 0, contents_rect.width(), contents_rect.height()); + View::PaintChildren(&contents_canvas); // We want the contents background to be slightly transparent so we can see - // the blurry glass effect on DWM systems behind. + // the blurry glass effect on DWM systems behind. We do this _after_ we paint + // the children since they paint text, and GDI will reset this alpha data if + // we paint text after this call. MakeCanvasTransparent(&contents_canvas); - View::PaintChildren(&contents_canvas); // Now paint the contents of the contents canvas into the actual canvas. SkPaint paint; diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h index 30a4306..9afeb0d 100644 --- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h +++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h @@ -8,6 +8,7 @@ #include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/autocomplete/autocomplete_popup_model.h" #include "chrome/browser/autocomplete/autocomplete_popup_view.h" +#include "chrome/common/gfx/chrome_font.h" #include "chrome/views/view.h" class AutocompleteEditModel; @@ -32,7 +33,7 @@ class AutocompleteResultViewModel { virtual bool IsSelectedIndex(size_t index) = 0; // Returns the type of match that the row corresponds to. - virtual AutocompleteMatch::Type GetResultTypeAtIndex(size_t index) = 0; + virtual const AutocompleteMatch& GetMatchAtIndex(size_t index) = 0; // Called when the line at the specified index should be opened with the // provided disposition. @@ -74,7 +75,7 @@ class AutocompletePopupContentsView : public views::View, // Overridden from AutocompleteResultViewModel: virtual bool IsSelectedIndex(size_t index); - virtual AutocompleteMatch::Type GetResultTypeAtIndex(size_t index); + virtual const AutocompleteMatch& GetMatchAtIndex(size_t index); virtual void OpenIndex(size_t index, WindowOpenDisposition disposition); virtual void SetHoveredLine(size_t index); virtual void SetSelectedLine(size_t index, bool revert_to_default); @@ -106,6 +107,10 @@ class AutocompletePopupContentsView : public views::View, // An object that tells the popup how to position itself. AutocompletePopupPositioner* popup_positioner_; + // The font used by the edit that created us. This is used by the result + // views to synthesize a suitable display font. + ChromeFont edit_font_; + DISALLOW_COPY_AND_ASSIGN(AutocompletePopupContentsView); }; |