| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/libgtk2ui/gtk2_ui.h" | 5 #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <pango/pango.h> | 8 #include <pango/pango.h> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 default: | 466 default: |
| 467 return views::LinuxUI::MIDDLE_CLICK_ACTION_LOWER; | 467 return views::LinuxUI::MIDDLE_CLICK_ACTION_LOWER; |
| 468 } | 468 } |
| 469 } | 469 } |
| 470 | 470 |
| 471 } // namespace | 471 } // namespace |
| 472 | 472 |
| 473 Gtk2UI::Gtk2UI() | 473 Gtk2UI::Gtk2UI() |
| 474 : default_font_size_pixels_(0), | 474 : default_font_size_pixels_(0), |
| 475 default_font_style_(gfx::Font::NORMAL), | 475 default_font_style_(gfx::Font::NORMAL), |
| 476 default_font_weight_(gfx::Font::Weight::NORMAL), |
| 476 middle_click_action_(GetDefaultMiddleClickAction()), | 477 middle_click_action_(GetDefaultMiddleClickAction()), |
| 477 device_scale_factor_(1.0) { | 478 device_scale_factor_(1.0) { |
| 478 GtkInitFromCommandLine(*base::CommandLine::ForCurrentProcess()); | 479 GtkInitFromCommandLine(*base::CommandLine::ForCurrentProcess()); |
| 479 } | 480 } |
| 480 | 481 |
| 481 | 482 |
| 482 | 483 |
| 483 void OnThemeChanged(GObject* obj, GParamSpec* param, Gtk2UI* gtkui) { | 484 void OnThemeChanged(GObject* obj, GParamSpec* param, Gtk2UI* gtkui) { |
| 484 gtkui->ResetStyle(); | 485 gtkui->ResetStyle(); |
| 485 } | 486 } |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 } | 817 } |
| 817 | 818 |
| 818 gfx::FontRenderParams Gtk2UI::GetDefaultFontRenderParams() const { | 819 gfx::FontRenderParams Gtk2UI::GetDefaultFontRenderParams() const { |
| 819 static gfx::FontRenderParams params = GetGtkFontRenderParams(); | 820 static gfx::FontRenderParams params = GetGtkFontRenderParams(); |
| 820 return params; | 821 return params; |
| 821 } | 822 } |
| 822 | 823 |
| 823 void Gtk2UI::GetDefaultFontDescription( | 824 void Gtk2UI::GetDefaultFontDescription( |
| 824 std::string* family_out, | 825 std::string* family_out, |
| 825 int* size_pixels_out, | 826 int* size_pixels_out, |
| 826 int* style_out, | 827 bool* italic_out, |
| 828 gfx::Font::Weight* weight_out, |
| 827 gfx::FontRenderParams* params_out) const { | 829 gfx::FontRenderParams* params_out) const { |
| 828 *family_out = default_font_family_; | 830 *family_out = default_font_family_; |
| 829 *size_pixels_out = default_font_size_pixels_; | 831 *size_pixels_out = default_font_size_pixels_; |
| 830 *style_out = default_font_style_; | 832 *italic_out = (default_font_style_ & gfx::Font::ITALIC) != 0; |
| 833 *weight_out = default_font_weight_; |
| 831 *params_out = default_font_render_params_; | 834 *params_out = default_font_render_params_; |
| 832 } | 835 } |
| 833 | 836 |
| 834 ui::SelectFileDialog* Gtk2UI::CreateSelectFileDialog( | 837 ui::SelectFileDialog* Gtk2UI::CreateSelectFileDialog( |
| 835 ui::SelectFileDialog::Listener* listener, | 838 ui::SelectFileDialog::Listener* listener, |
| 836 ui::SelectFilePolicy* policy) const { | 839 ui::SelectFilePolicy* policy) const { |
| 837 return SelectFileDialogImpl::Create(listener, policy); | 840 return SelectFileDialogImpl::Create(listener, policy); |
| 838 } | 841 } |
| 839 | 842 |
| 840 bool Gtk2UI::UnityIsRunning() { | 843 bool Gtk2UI::UnityIsRunning() { |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1347 // Non-absolute sizes are in points (again scaled by PANGO_SIZE). | 1350 // Non-absolute sizes are in points (again scaled by PANGO_SIZE). |
| 1348 // Round the value when converting to pixels to match GTK's logic. | 1351 // Round the value when converting to pixels to match GTK's logic. |
| 1349 const double size_points = pango_font_description_get_size(desc) / | 1352 const double size_points = pango_font_description_get_size(desc) / |
| 1350 static_cast<double>(PANGO_SCALE); | 1353 static_cast<double>(PANGO_SCALE); |
| 1351 default_font_size_pixels_ = static_cast<int>( | 1354 default_font_size_pixels_ = static_cast<int>( |
| 1352 GetPixelsInPoint(device_scale_factor_) * size_points + 0.5); | 1355 GetPixelsInPoint(device_scale_factor_) * size_points + 0.5); |
| 1353 query.point_size = static_cast<int>(size_points); | 1356 query.point_size = static_cast<int>(size_points); |
| 1354 } | 1357 } |
| 1355 | 1358 |
| 1356 query.style = gfx::Font::NORMAL; | 1359 query.style = gfx::Font::NORMAL; |
| 1357 // TODO(davemoore): Support weights other than bold? | 1360 query.weight = |
| 1358 if (pango_font_description_get_weight(desc) == PANGO_WEIGHT_BOLD) | 1361 static_cast<gfx::Font::Weight>(pango_font_description_get_weight(desc)); |
| 1359 query.style |= gfx::Font::BOLD; | |
| 1360 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE? | 1362 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE? |
| 1361 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) | 1363 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) |
| 1362 query.style |= gfx::Font::ITALIC; | 1364 query.style |= gfx::Font::ITALIC; |
| 1363 | 1365 |
| 1364 default_font_render_params_ = | 1366 default_font_render_params_ = |
| 1365 gfx::GetFontRenderParams(query, &default_font_family_); | 1367 gfx::GetFontRenderParams(query, &default_font_family_); |
| 1366 default_font_style_ = query.style; | 1368 default_font_style_ = query.style; |
| 1367 } | 1369 } |
| 1368 | 1370 |
| 1369 void Gtk2UI::ResetStyle() { | 1371 void Gtk2UI::ResetStyle() { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1389 // Blacklist scaling factors <130% (crbug.com/484400) and round | 1391 // Blacklist scaling factors <130% (crbug.com/484400) and round |
| 1390 // to 1 decimal to prevent rendering problems (crbug.com/485183). | 1392 // to 1 decimal to prevent rendering problems (crbug.com/485183). |
| 1391 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10; | 1393 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10; |
| 1392 } | 1394 } |
| 1393 | 1395 |
| 1394 } // namespace libgtk2ui | 1396 } // namespace libgtk2ui |
| 1395 | 1397 |
| 1396 views::LinuxUI* BuildGtk2UI() { | 1398 views::LinuxUI* BuildGtk2UI() { |
| 1397 return new libgtk2ui::Gtk2UI; | 1399 return new libgtk2ui::Gtk2UI; |
| 1398 } | 1400 } |
| OLD | NEW |