diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-20 22:07:11 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-20 22:07:11 +0000 |
commit | d7fc97946625fee2c54e18bce4f61608efeeef03 (patch) | |
tree | e2033035f58d2342f55cdb677e38d281cc655152 | |
parent | b12d815dbd8295b3e7f5e4b4a7350aebc580270c (diff) | |
download | chromium_src-d7fc97946625fee2c54e18bce4f61608efeeef03.zip chromium_src-d7fc97946625fee2c54e18bce4f61608efeeef03.tar.gz chromium_src-d7fc97946625fee2c54e18bce4f61608efeeef03.tar.bz2 |
Fixes two issues from valgrind, and some cleanup:
. Makes it so observer installed by WidgetGtk is cleaned up and not
leaked.
. Removes unnecessary static_cast<int> in view.
. Fixes some leaks in textfield and button.
. Removes AutocompletePopupViewGTK's copy of PangoFontFromGfxFont.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/420005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32686 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc | 29 | ||||
-rw-r--r-- | views/controls/button/native_button_gtk.cc | 7 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_gtk.cc | 6 | ||||
-rw-r--r-- | views/view.cc | 3 | ||||
-rw-r--r-- | views/widget/widget_gtk.cc | 11 |
5 files changed, 18 insertions, 38 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc index b22944b..13c62d2 100644 --- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc +++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc @@ -67,33 +67,6 @@ const float kContentWidthPercentage = 0.7; // UTF-8 Left-to-right embedding. const char* kLRE = "\xe2\x80\xaa"; -// TODO(deanm): We should put this on gfx::Font so it can be shared. -// Returns a new pango font, free with pango_font_description_free(). -PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& chrome_font) { - gfx::Font font = chrome_font; // Copy so we can call non-const methods. - PangoFontDescription* pfd = pango_font_description_new(); - pango_font_description_set_family(pfd, WideToUTF8(font.FontName()).c_str()); - pango_font_description_set_size(pfd, font.FontSize() * PANGO_SCALE); - - switch (font.style()) { - case gfx::Font::NORMAL: - // Nothing to do, should already be PANGO_STYLE_NORMAL. - break; - case gfx::Font::BOLD: - pango_font_description_set_weight(pfd, PANGO_WEIGHT_BOLD); - break; - case gfx::Font::ITALIC: - pango_font_description_set_style(pfd, PANGO_STYLE_ITALIC); - break; - case gfx::Font::UNDERLINED: - // TODO(deanm): How to do underlined? Where do we use it? Probably have - // to paint it ourselves, see pango_font_metrics_get_underline_position. - break; - } - - return pfd; -} - // Return a Rect covering the whole area of |window|. gfx::Rect GetWindowRect(GdkWindow* window) { gint width, height; @@ -271,7 +244,7 @@ AutocompletePopupViewGtk::AutocompletePopupViewGtk( // For now, force the font size. gfx::Font font = gfx::Font::CreateFont( gfx::Font().FontName(), browser_defaults::kAutocompletePopupFontSize); - PangoFontDescription* pfd = PangoFontFromGfxFont(font); + PangoFontDescription* pfd = gfx::Font::PangoFontFromGfxFont(font); pango_layout_set_font_description(layout_, pfd); pango_font_description_free(pfd); diff --git a/views/controls/button/native_button_gtk.cc b/views/controls/button/native_button_gtk.cc index 17a25e2..e663db6 100644 --- a/views/controls/button/native_button_gtk.cc +++ b/views/controls/button/native_button_gtk.cc @@ -40,9 +40,10 @@ void NativeButtonGtk::UpdateFont() { if (!native_view()) return; - gtk_widget_modify_font( - native_view(), - gfx::Font::PangoFontFromGfxFont(native_button_->font())); + PangoFontDescription* pfd = + gfx::Font::PangoFontFromGfxFont(native_button_->font()); + gtk_widget_modify_font(native_view(), pfd); + pango_font_description_free(pfd); preferred_size_ = gfx::Size(); } diff --git a/views/controls/textfield/native_textfield_gtk.cc b/views/controls/textfield/native_textfield_gtk.cc index 911ae38..9728a1d 100644 --- a/views/controls/textfield/native_textfield_gtk.cc +++ b/views/controls/textfield/native_textfield_gtk.cc @@ -121,8 +121,10 @@ void NativeTextfieldGtk::UpdateReadOnly() { void NativeTextfieldGtk::UpdateFont() { if (!native_view()) return; - gtk_widget_modify_font(native_view(), - gfx::Font::PangoFontFromGfxFont(textfield_->font())); + PangoFontDescription* pfd = + gfx::Font::PangoFontFromGfxFont(textfield_->font()); + gtk_widget_modify_font(native_view(), pfd); + pango_font_description_free(pfd); } void NativeTextfieldGtk::UpdateEnabled() { diff --git a/views/view.cc b/views/view.cc index 839616e..3450e9a 100644 --- a/views/view.cc +++ b/views/view.cc @@ -417,8 +417,7 @@ gfx::NativeCursor View::GetCursorForPoint(Event::EventType event_type, int x, } bool View::HitTest(const gfx::Point& l) const { - if (l.x() >= 0 && l.x() < static_cast<int>(width()) && - l.y() >= 0 && l.y() < static_cast<int>(height())) { + if (l.x() >= 0 && l.x() < width() && l.y() >= 0 && l.y() < height()) { if (HasHitTestMask()) { gfx::Path mask; GetHitTestMask(&mask); diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index 8762e14..87fdb8d 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -25,7 +25,11 @@ namespace views { // drag-leave that GTK generates. class WidgetGtk::DropObserver : public MessageLoopForUI::Observer { public: - DropObserver() { } + DropObserver() {} + + static DropObserver* Get() { + return Singleton<DropObserver>::get(); + } virtual void WillProcessEvent(GdkEvent* event) { if (event->type == GDK_DROP_START) { @@ -98,7 +102,7 @@ WidgetGtk::WidgetGtk(Type type) installed_message_loop_observer = true; MessageLoopForUI* loop = MessageLoopForUI::current(); if (loop) - loop->AddObserver(new DropObserver()); + loop->AddObserver(DropObserver::Get()); } if (type_ != TYPE_CHILD) @@ -1082,7 +1086,8 @@ gboolean WidgetGtk::CallQueryTooltip(GtkWidget* widget, gboolean keyboard_mode, GtkTooltip* tooltip, WidgetGtk* host) { - return host->OnQueryTooltip(x, y, keyboard_mode, tooltip); + return host->OnQueryTooltip(static_cast<int>(x), static_cast<int>(y), + keyboard_mode, tooltip); } gboolean WidgetGtk::CallScroll(GtkWidget* widget, GdkEventScroll* event) { |