Commit 76769350 authored by erg@chromium.org's avatar erg@chromium.org

GTK: Draw the correct omnibox state with new tab-to-traverse behavior.

This does everything but animate the trailing ">" icon from the right
side of the omnibox to the left when entering tab-to-search mode. The
TTS arrow indicator is now properly GTK themed, as well.

(Doing the animation is lower priority. It would require more
extensive refactoring that I don't have time for as I have code yellow work.)

BUG=116292
TEST=all new tab-to-search behavior matches views sans animation.


Review URL: http://codereview.chromium.org/9562029

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124552 0039d316-1c4b-4281-b951-d872f2087c98
parent c89adc7b
...@@ -488,7 +488,9 @@ void OmniboxPopupViewGtk::AcceptLine(size_t line, ...@@ -488,7 +488,9 @@ void OmniboxPopupViewGtk::AcceptLine(size_t line,
} }
const gfx::Image* OmniboxPopupViewGtk::IconForMatch( const gfx::Image* OmniboxPopupViewGtk::IconForMatch(
const AutocompleteMatch& match, bool selected) { const AutocompleteMatch& match,
bool selected,
bool is_selected_keyword) {
const SkBitmap* bitmap = model_->GetIconIfExtensionMatch(match); const SkBitmap* bitmap = model_->GetIconIfExtensionMatch(match);
if (bitmap) { if (bitmap) {
if (!ContainsKey(images_, bitmap)) { if (!ContainsKey(images_, bitmap)) {
...@@ -499,8 +501,14 @@ const gfx::Image* OmniboxPopupViewGtk::IconForMatch( ...@@ -499,8 +501,14 @@ const gfx::Image* OmniboxPopupViewGtk::IconForMatch(
return images_[bitmap]; return images_[bitmap];
} }
int icon = match.starred ? int icon;
IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match.type); if (is_selected_keyword)
icon = IDR_OMNIBOX_TTS;
else if (match.starred)
icon = IDR_OMNIBOX_STAR;
else
icon = AutocompleteMatch::TypeToIcon(match.type);
if (selected) { if (selected) {
switch (icon) { switch (icon) {
case IDR_OMNIBOX_EXTENSION_APP: case IDR_OMNIBOX_EXTENSION_APP:
...@@ -518,6 +526,9 @@ const gfx::Image* OmniboxPopupViewGtk::IconForMatch( ...@@ -518,6 +526,9 @@ const gfx::Image* OmniboxPopupViewGtk::IconForMatch(
case IDR_OMNIBOX_STAR: case IDR_OMNIBOX_STAR:
icon = IDR_OMNIBOX_STAR_DARK; icon = IDR_OMNIBOX_STAR_DARK;
break; break;
case IDR_OMNIBOX_TTS:
icon = IDR_OMNIBOX_TTS_DARK;
break;
default: default:
NOTREACHED(); NOTREACHED();
break; break;
...@@ -527,6 +538,24 @@ const gfx::Image* OmniboxPopupViewGtk::IconForMatch( ...@@ -527,6 +538,24 @@ const gfx::Image* OmniboxPopupViewGtk::IconForMatch(
return theme_service_->GetImageNamed(icon); return theme_service_->GetImageNamed(icon);
} }
void OmniboxPopupViewGtk::GetVisibleMatchForInput(
size_t index,
const AutocompleteMatch** match,
bool* is_selected_keyword) {
const AutocompleteResult& result = model_->result();
if (result.match_at(index).associated_keyword.get() &&
model_->selected_line() == index &&
model_->selected_line_state() == AutocompletePopupModel::KEYWORD) {
*match = result.match_at(index).associated_keyword.get();
*is_selected_keyword = true;
return;
}
*match = &result.match_at(index);
*is_selected_keyword = false;
}
gboolean OmniboxPopupViewGtk::HandleMotion(GtkWidget* widget, gboolean OmniboxPopupViewGtk::HandleMotion(GtkWidget* widget,
GdkEventMotion* event) { GdkEventMotion* event) {
// TODO(deanm): Windows has a bunch of complicated logic here. // TODO(deanm): Windows has a bunch of complicated logic here.
...@@ -610,7 +639,9 @@ gboolean OmniboxPopupViewGtk::HandleExpose(GtkWidget* widget, ...@@ -610,7 +639,9 @@ gboolean OmniboxPopupViewGtk::HandleExpose(GtkWidget* widget,
if (!line_rect.Intersects(damage_rect)) if (!line_rect.Intersects(damage_rect))
continue; continue;
const AutocompleteMatch& match = result.match_at(i); const AutocompleteMatch* match = NULL;
bool is_selected_keyword = false;
GetVisibleMatchForInput(i, &match, &is_selected_keyword);
bool is_selected = (model_->selected_line() == i); bool is_selected = (model_->selected_line() == i);
bool is_hovered = (model_->hovered_line() == i); bool is_hovered = (model_->hovered_line() == i);
if (is_selected || is_hovered) { if (is_selected || is_hovered) {
...@@ -626,20 +657,20 @@ gboolean OmniboxPopupViewGtk::HandleExpose(GtkWidget* widget, ...@@ -626,20 +657,20 @@ gboolean OmniboxPopupViewGtk::HandleExpose(GtkWidget* widget,
(line_rect.width() - kIconLeftPadding - kIconWidth); (line_rect.width() - kIconLeftPadding - kIconWidth);
// Draw the icon for this result. // Draw the icon for this result.
DrawFullImage(cr, widget, DrawFullImage(cr, widget,
IconForMatch(match, is_selected), IconForMatch(*match, is_selected, is_selected_keyword),
icon_start_x, line_rect.y() + kIconTopPadding); icon_start_x, line_rect.y() + kIconTopPadding);
// Draw the results text vertically centered in the results space. // Draw the results text vertically centered in the results space.
// First draw the contents / url, but don't let it take up the whole width // First draw the contents / url, but don't let it take up the whole width
// if there is also a description to be shown. // if there is also a description to be shown.
bool has_description = !match.description.empty(); bool has_description = !match->description.empty();
int text_width = window_rect.width() - (kIconAreaWidth + kRightPadding); int text_width = window_rect.width() - (kIconAreaWidth + kRightPadding);
int allocated_content_width = has_description ? int allocated_content_width = has_description ?
static_cast<int>(text_width * kContentWidthPercentage) : text_width; static_cast<int>(text_width * kContentWidthPercentage) : text_width;
pango_layout_set_width(layout_, allocated_content_width * PANGO_SCALE); pango_layout_set_width(layout_, allocated_content_width * PANGO_SCALE);
// Note: We force to URL to LTR for all text directions. // Note: We force to URL to LTR for all text directions.
SetupLayoutForMatch(layout_, match.contents, match.contents_class, SetupLayoutForMatch(layout_, match->contents, match->contents_class,
is_selected ? &selected_content_text_color_ : is_selected ? &selected_content_text_color_ :
&content_text_color_, &content_text_color_,
is_selected ? &selected_content_dim_text_color_ : is_selected ? &selected_content_dim_text_color_ :
...@@ -674,7 +705,7 @@ gboolean OmniboxPopupViewGtk::HandleExpose(GtkWidget* widget, ...@@ -674,7 +705,7 @@ gboolean OmniboxPopupViewGtk::HandleExpose(GtkWidget* widget,
// In Windows, a boolean "force_dim" is passed as true for the // In Windows, a boolean "force_dim" is passed as true for the
// description. Here, we pass the dim text color for both normal and dim, // description. Here, we pass the dim text color for both normal and dim,
// to accomplish the same thing. // to accomplish the same thing.
SetupLayoutForMatch(layout_, match.description, match.description_class, SetupLayoutForMatch(layout_, match->description, match->description_class,
is_selected ? &selected_content_dim_text_color_ : is_selected ? &selected_content_dim_text_color_ :
&content_dim_text_color_, &content_dim_text_color_,
is_selected ? &selected_content_dim_text_color_ : is_selected ? &selected_content_dim_text_color_ :
...@@ -694,6 +725,18 @@ gboolean OmniboxPopupViewGtk::HandleExpose(GtkWidget* widget, ...@@ -694,6 +725,18 @@ gboolean OmniboxPopupViewGtk::HandleExpose(GtkWidget* widget,
pango_cairo_show_layout(cr, layout_); pango_cairo_show_layout(cr, layout_);
cairo_restore(cr); cairo_restore(cr);
} }
if (match->associated_keyword.get()) {
// If this entry has an associated keyword, draw the arrow at the extreme
// other side of the omnibox.
icon_start_x = ltr ? (line_rect.width() - kIconLeftPadding - kIconWidth) :
kIconLeftPadding;
// Draw the icon for this result.
DrawFullImage(cr, widget,
theme_service_->GetImageNamed(
is_selected ? IDR_OMNIBOX_TTS_DARK : IDR_OMNIBOX_TTS),
icon_start_x, line_rect.y() + kIconTopPadding);
}
} }
cairo_destroy(cr); cairo_destroy(cr);
......
...@@ -79,7 +79,15 @@ class OmniboxPopupViewGtk : public AutocompletePopupView, ...@@ -79,7 +79,15 @@ class OmniboxPopupViewGtk : public AutocompletePopupView,
// Accept a line of the results, for example, when the user clicks a line. // Accept a line of the results, for example, when the user clicks a line.
void AcceptLine(size_t line, WindowOpenDisposition disposition); void AcceptLine(size_t line, WindowOpenDisposition disposition);
const gfx::Image* IconForMatch(const AutocompleteMatch& match, bool selected); const gfx::Image* IconForMatch(const AutocompleteMatch& match,
bool selected,
bool is_selected_keyword);
// Returns the |index|th element of match, unless we're selected and showing
// the associated keyword match.
void GetVisibleMatchForInput(size_t index,
const AutocompleteMatch** match,
bool* is_selected_keyword);
CHROMEGTK_CALLBACK_1(OmniboxPopupViewGtk, gboolean, HandleMotion, CHROMEGTK_CALLBACK_1(OmniboxPopupViewGtk, gboolean, HandleMotion,
GdkEventMotion*); GdkEventMotion*);
......
...@@ -109,6 +109,8 @@ const int kAutocompleteImages[] = { ...@@ -109,6 +109,8 @@ const int kAutocompleteImages[] = {
IDR_OMNIBOX_SEARCH_DARK, IDR_OMNIBOX_SEARCH_DARK,
IDR_OMNIBOX_STAR, IDR_OMNIBOX_STAR,
IDR_OMNIBOX_STAR_DARK, IDR_OMNIBOX_STAR_DARK,
IDR_OMNIBOX_TTS,
IDR_OMNIBOX_TTS_DARK,
IDR_GEOLOCATION_ALLOWED_LOCATIONBAR_ICON, IDR_GEOLOCATION_ALLOWED_LOCATIONBAR_ICON,
IDR_GEOLOCATION_DENIED_LOCATIONBAR_ICON, IDR_GEOLOCATION_DENIED_LOCATIONBAR_ICON,
}; };
...@@ -965,6 +967,7 @@ SkBitmap* ThemeServiceGtk::GenerateGtkThemeBitmap(int id) const { ...@@ -965,6 +967,7 @@ SkBitmap* ThemeServiceGtk::GenerateGtkThemeBitmap(int id) const {
case IDR_OMNIBOX_HTTP: case IDR_OMNIBOX_HTTP:
case IDR_OMNIBOX_SEARCH: case IDR_OMNIBOX_SEARCH:
case IDR_OMNIBOX_STAR: case IDR_OMNIBOX_STAR:
case IDR_OMNIBOX_TTS:
case IDR_GEOLOCATION_ALLOWED_LOCATIONBAR_ICON: case IDR_GEOLOCATION_ALLOWED_LOCATIONBAR_ICON:
case IDR_GEOLOCATION_DENIED_LOCATIONBAR_ICON: { case IDR_GEOLOCATION_DENIED_LOCATIONBAR_ICON: {
return GenerateTintedIcon(id, entry_tint_); return GenerateTintedIcon(id, entry_tint_);
...@@ -977,7 +980,8 @@ SkBitmap* ThemeServiceGtk::GenerateGtkThemeBitmap(int id) const { ...@@ -977,7 +980,8 @@ SkBitmap* ThemeServiceGtk::GenerateGtkThemeBitmap(int id) const {
case IDR_OMNIBOX_HISTORY_DARK: case IDR_OMNIBOX_HISTORY_DARK:
case IDR_OMNIBOX_HTTP_DARK: case IDR_OMNIBOX_HTTP_DARK:
case IDR_OMNIBOX_SEARCH_DARK: case IDR_OMNIBOX_SEARCH_DARK:
case IDR_OMNIBOX_STAR_DARK: { case IDR_OMNIBOX_STAR_DARK:
case IDR_OMNIBOX_TTS_DARK: {
return GenerateTintedIcon(id, selected_entry_tint_); return GenerateTintedIcon(id, selected_entry_tint_);
} }
default: { default: {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment