| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" | 5 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 // Space between the left edge (including the border) and the text. | 53 // Space between the left edge (including the border) and the text. |
| 54 const int kIconAreaWidth = | 54 const int kIconAreaWidth = |
| 55 kIconLeftPadding + kIconWidth + kIconRightPadding; | 55 kIconLeftPadding + kIconWidth + kIconRightPadding; |
| 56 // Space between the right edge (including the border) and the text. | 56 // Space between the right edge (including the border) and the text. |
| 57 const int kRightPadding = 3; | 57 const int kRightPadding = 3; |
| 58 // When we have both a content and description string, we don't want the | 58 // When we have both a content and description string, we don't want the |
| 59 // content to push the description off. Limit the content to a percentage of | 59 // content to push the description off. Limit the content to a percentage of |
| 60 // the total width. | 60 // the total width. |
| 61 const float kContentWidthPercentage = 0.7; | 61 const float kContentWidthPercentage = 0.7; |
| 62 | 62 |
| 63 // TODO(deanm): We should put this on ChromeFont so it can be shared. | 63 // TODO(deanm): We should put this on gfx::Font so it can be shared. |
| 64 // Returns a new pango font, free with pango_font_description_free(). | 64 // Returns a new pango font, free with pango_font_description_free(). |
| 65 PangoFontDescription* PangoFontFromChromeFont(const ChromeFont& chrome_font) { | 65 PangoFontDescription* PangoFontFromGfxFont(const gfx::Font& chrome_font) { |
| 66 ChromeFont font = chrome_font; // Copy so we can call non-const methods. | 66 gfx::Font font = chrome_font; // Copy so we can call non-const methods. |
| 67 PangoFontDescription* pfd = pango_font_description_new(); | 67 PangoFontDescription* pfd = pango_font_description_new(); |
| 68 pango_font_description_set_family(pfd, WideToUTF8(font.FontName()).c_str()); | 68 pango_font_description_set_family(pfd, WideToUTF8(font.FontName()).c_str()); |
| 69 pango_font_description_set_size(pfd, font.FontSize() * PANGO_SCALE); | 69 pango_font_description_set_size(pfd, font.FontSize() * PANGO_SCALE); |
| 70 | 70 |
| 71 switch (font.style()) { | 71 switch (font.style()) { |
| 72 case ChromeFont::NORMAL: | 72 case gfx::Font::NORMAL: |
| 73 // Nothing to do, should already be PANGO_STYLE_NORMAL. | 73 // Nothing to do, should already be PANGO_STYLE_NORMAL. |
| 74 break; | 74 break; |
| 75 case ChromeFont::BOLD: | 75 case gfx::Font::BOLD: |
| 76 pango_font_description_set_weight(pfd, PANGO_WEIGHT_BOLD); | 76 pango_font_description_set_weight(pfd, PANGO_WEIGHT_BOLD); |
| 77 break; | 77 break; |
| 78 case ChromeFont::ITALIC: | 78 case gfx::Font::ITALIC: |
| 79 pango_font_description_set_style(pfd, PANGO_STYLE_ITALIC); | 79 pango_font_description_set_style(pfd, PANGO_STYLE_ITALIC); |
| 80 break; | 80 break; |
| 81 case ChromeFont::UNDERLINED: | 81 case gfx::Font::UNDERLINED: |
| 82 // TODO(deanm): How to do underlined? Where do we use it? Probably have | 82 // TODO(deanm): How to do underlined? Where do we use it? Probably have |
| 83 // to paint it ourselves, see pango_font_metrics_get_underline_position. | 83 // to paint it ourselves, see pango_font_metrics_get_underline_position. |
| 84 break; | 84 break; |
| 85 } | 85 } |
| 86 | 86 |
| 87 return pfd; | 87 return pfd; |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Return a Rect covering the whole area of |window|. | 90 // Return a Rect covering the whole area of |window|. |
| 91 gfx::Rect GetWindowRect(GdkWindow* window) { | 91 gfx::Rect GetWindowRect(GdkWindow* window) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 // Set the background color, so we don't need to paint it manually. | 239 // Set the background color, so we don't need to paint it manually. |
| 240 gtk_widget_modify_bg(window_, GTK_STATE_NORMAL, &kBackgroundColor); | 240 gtk_widget_modify_bg(window_, GTK_STATE_NORMAL, &kBackgroundColor); |
| 241 | 241 |
| 242 // Cache the layout so we don't have to create it for every expose. If we | 242 // Cache the layout so we don't have to create it for every expose. If we |
| 243 // were a real widget we should handle changing directions, but we're not | 243 // were a real widget we should handle changing directions, but we're not |
| 244 // doing RTL or anything yet, so it shouldn't be important now. | 244 // doing RTL or anything yet, so it shouldn't be important now. |
| 245 layout_ = gtk_widget_create_pango_layout(window_, NULL); | 245 layout_ = gtk_widget_create_pango_layout(window_, NULL); |
| 246 // We always ellipsize when drawing our text runs. | 246 // We always ellipsize when drawing our text runs. |
| 247 pango_layout_set_ellipsize(layout_, PANGO_ELLIPSIZE_END); | 247 pango_layout_set_ellipsize(layout_, PANGO_ELLIPSIZE_END); |
| 248 // TODO(deanm): We might want to eventually follow what Windows does and | 248 // TODO(deanm): We might want to eventually follow what Windows does and |
| 249 // plumb a ChromeFont through. This is because popup windows have a | 249 // plumb a gfx::Font through. This is because popup windows have a |
| 250 // different font size, although we could just derive that font here. | 250 // different font size, although we could just derive that font here. |
| 251 PangoFontDescription* pfd = PangoFontFromChromeFont(ChromeFont()); | 251 PangoFontDescription* pfd = PangoFontFromGfxFont(gfx::Font()); |
| 252 pango_layout_set_font_description(layout_, pfd); | 252 pango_layout_set_font_description(layout_, pfd); |
| 253 pango_font_description_free(pfd); | 253 pango_font_description_free(pfd); |
| 254 | 254 |
| 255 gtk_widget_add_events(window_, GDK_BUTTON_MOTION_MASK | | 255 gtk_widget_add_events(window_, GDK_BUTTON_MOTION_MASK | |
| 256 GDK_POINTER_MOTION_MASK | | 256 GDK_POINTER_MOTION_MASK | |
| 257 GDK_BUTTON_PRESS_MASK | | 257 GDK_BUTTON_PRESS_MASK | |
| 258 GDK_BUTTON_RELEASE_MASK); | 258 GDK_BUTTON_RELEASE_MASK); |
| 259 g_signal_connect(window_, "motion-notify-event", | 259 g_signal_connect(window_, "motion-notify-event", |
| 260 G_CALLBACK(&HandleMotionThunk), this); | 260 G_CALLBACK(&HandleMotionThunk), this); |
| 261 g_signal_connect(window_, "button-press-event", | 261 g_signal_connect(window_, "button-press-event", |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 gdk_draw_layout(drawable, gc, | 473 gdk_draw_layout(drawable, gc, |
| 474 kIconAreaWidth + actual_content_width, content_y, | 474 kIconAreaWidth + actual_content_width, content_y, |
| 475 layout_); | 475 layout_); |
| 476 } | 476 } |
| 477 } | 477 } |
| 478 | 478 |
| 479 g_object_unref(gc); | 479 g_object_unref(gc); |
| 480 | 480 |
| 481 return TRUE; | 481 return TRUE; |
| 482 } | 482 } |
| OLD | NEW |