summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-11-18 18:32:45 +0000
committerBen Murdoch <benm@google.com>2010-11-18 18:38:07 +0000
commit513209b27ff55e2841eac0e4120199c23acce758 (patch)
treeaeba30bb08c5f47c57003544e378a377c297eee6 /chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
parent164f7496de0fbee436b385a79ead9e3cb81a50c1 (diff)
downloadexternal_chromium-513209b27ff55e2841eac0e4120199c23acce758.zip
external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.gz
external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.bz2
Merge Chromium at r65505: Initial merge by git.
Change-Id: I31d8f1d8cd33caaf7f47ffa7350aef42d5fbdb45
Diffstat (limited to 'chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc')
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc138
1 files changed, 75 insertions, 63 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
index aaf7e05..088c9ad 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/gtk/gtk_theme_provider.h"
@@ -109,9 +110,68 @@ size_t GetUTF8Offset(const std::wstring& wide_text, size_t wide_text_offset) {
return WideToUTF8(wide_text.substr(0, wide_text_offset)).size();
}
-void SetupLayoutForMatch(PangoLayout* layout,
+// Generates the normal URL color, a green color used in unhighlighted URL
+// text. It is a mix of |kURLTextColor| and the current text color. Unlike the
+// selected text color, it is more important to match the qualities of the
+// foreground typeface color instead of taking the background into account.
+GdkColor NormalURLColor(GdkColor foreground) {
+ color_utils::HSL fg_hsl;
+ color_utils::SkColorToHSL(gfx::GdkColorToSkColor(foreground), &fg_hsl);
+
+ color_utils::HSL hue_hsl;
+ color_utils::SkColorToHSL(gfx::GdkColorToSkColor(kURLTextColor), &hue_hsl);
+
+ // Only allow colors that have a fair amount of saturation in them (color vs
+ // white). This means that our output color will always be fairly green.
+ double s = std::max(0.5, fg_hsl.s);
+
+ // Make sure the luminance is at least as bright as the |kURLTextColor| green
+ // would be if we were to use that.
+ double l;
+ if (fg_hsl.l < hue_hsl.l)
+ l = hue_hsl.l;
+ else
+ l = (fg_hsl.l + hue_hsl.l) / 2;
+
+ color_utils::HSL output = { hue_hsl.h, s, l };
+ return gfx::SkColorToGdkColor(color_utils::HSLToSkColor(output, 255));
+}
+
+// Generates the selected URL color, a green color used on URL text in the
+// currently highlighted entry in the autocomplete popup. It's a mix of
+// |kURLTextColor|, the current text color, and the background color (the
+// select highlight). It is more important to contrast with the background
+// saturation than to look exactly like the foreground color.
+GdkColor SelectedURLColor(GdkColor foreground, GdkColor background) {
+ color_utils::HSL fg_hsl;
+ color_utils::SkColorToHSL(gfx::GdkColorToSkColor(foreground), &fg_hsl);
+
+ color_utils::HSL bg_hsl;
+ color_utils::SkColorToHSL(gfx::GdkColorToSkColor(background), &bg_hsl);
+
+ color_utils::HSL hue_hsl;
+ color_utils::SkColorToHSL(gfx::GdkColorToSkColor(kURLTextColor), &hue_hsl);
+
+ // The saturation of the text should be opposite of the background, clamped
+ // to 0.2-0.8. We make sure it's greater than 0.2 so there's some color, but
+ // less than 0.8 so it's not the oversaturated neon-color.
+ double opposite_s = 1 - bg_hsl.s;
+ double s = std::max(0.2, std::min(0.8, opposite_s));
+
+ // The luminance should match the luminance of the foreground text. Again,
+ // we clamp so as to have at some amount of color (green) in the text.
+ double opposite_l = fg_hsl.l;
+ double l = std::max(0.1, std::min(0.9, opposite_l));
+
+ color_utils::HSL output = { hue_hsl.h, s, l };
+ return gfx::SkColorToGdkColor(color_utils::HSLToSkColor(output, 255));
+}
+} // namespace
+
+void AutocompletePopupViewGtk::SetupLayoutForMatch(
+ PangoLayout* layout,
const std::wstring& text,
- AutocompleteMatch::ACMatchClassifications classifications,
+ const AutocompleteMatch::ACMatchClassifications& classifications,
const GdkColor* base_color,
const GdkColor* dim_color,
const GdkColor* url_color,
@@ -195,65 +255,6 @@ void SetupLayoutForMatch(PangoLayout* layout,
pango_attr_list_unref(attrs);
}
-// Generates the normal URL color, a green color used in unhighlighted URL
-// text. It is a mix of |kURLTextColor| and the current text color. Unlike the
-// selected text color, It is more important to match the qualities of the
-// foreground typeface color instead of taking the background into account.
-GdkColor NormalURLColor(GdkColor foreground) {
- color_utils::HSL fg_hsl;
- color_utils::SkColorToHSL(gfx::GdkColorToSkColor(foreground), &fg_hsl);
-
- color_utils::HSL hue_hsl;
- color_utils::SkColorToHSL(gfx::GdkColorToSkColor(kURLTextColor), &hue_hsl);
-
- // Only allow colors that have a fair amount of saturation in them (color vs
- // white). This means that our output color will always be fairly green.
- double s = std::max(0.5, fg_hsl.s);
-
- // Make sure the luminance is at least as bright as the |kURLTextColor| green
- // would be if we were to use that.
- double l;
- if (fg_hsl.l < hue_hsl.l)
- l = hue_hsl.l;
- else
- l = (fg_hsl.l + hue_hsl.l) / 2;
-
- color_utils::HSL output = { hue_hsl.h, s, l };
- return gfx::SkColorToGdkColor(color_utils::HSLToSkColor(output, 255));
-}
-
-// Generates the selected URL color, a green color used on URL text in the
-// currently highlighted entry in the autocomplete popup. It's a mix of
-// |kURLTextColor|, the current text color, and the background color (the
-// select highlight). It is more important to contrast with the background
-// saturation than to look exactly like the foreground color.
-GdkColor SelectedURLColor(GdkColor foreground, GdkColor background) {
- color_utils::HSL fg_hsl;
- color_utils::SkColorToHSL(gfx::GdkColorToSkColor(foreground), &fg_hsl);
-
- color_utils::HSL bg_hsl;
- color_utils::SkColorToHSL(gfx::GdkColorToSkColor(background), &bg_hsl);
-
- color_utils::HSL hue_hsl;
- color_utils::SkColorToHSL(gfx::GdkColorToSkColor(kURLTextColor), &hue_hsl);
-
- // The saturation of the text should be opposite of the background, clamped
- // to 0.2-0.8. We make sure it's greater than 0.2 so there's some color, but
- // less than 0.8 so it's not the oversaturated neon-color.
- double opposite_s = 1 - bg_hsl.s;
- double s = std::max(0.2, std::min(0.8, opposite_s));
-
- // The luminance should match the luminance of the foreground text. Again,
- // we clamp so as to have at some amount of color (green) in the text.
- double opposite_l = fg_hsl.l;
- double l = std::max(0.1, std::min(0.9, opposite_l));
-
- color_utils::HSL output = { hue_hsl.h, s, l };
- return gfx::SkColorToGdkColor(color_utils::HSLToSkColor(output, 255));
-}
-
-} // namespace
-
AutocompletePopupViewGtk::AutocompletePopupViewGtk(
AutocompleteEditView* edit_view,
AutocompleteEditModel* edit_model,
@@ -356,9 +357,20 @@ void AutocompletePopupViewGtk::UpdatePopupAppearance() {
}
gfx::Rect AutocompletePopupViewGtk::GetTargetBounds() {
- return gfx::Rect();
-}
+ if (!GTK_WIDGET_REALIZED(window_))
+ return gfx::Rect();
+ gfx::Rect retval = gtk_util::GetWidgetScreenBounds(window_);
+
+ // The widget bounds don't update synchronously so may be out of sync with
+ // our last size request.
+ GtkRequisition req;
+ gtk_widget_size_request(window_, &req);
+ retval.set_width(req.width);
+ retval.set_height(req.height);
+
+ return retval;
+}
void AutocompletePopupViewGtk::PaintUpdatesNow() {
// Paint our queued invalidations now, synchronously.