| 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 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 } | 814 } |
| 814 | 815 |
| 815 gfx::FontRenderParams Gtk2UI::GetDefaultFontRenderParams() const { | 816 gfx::FontRenderParams Gtk2UI::GetDefaultFontRenderParams() const { |
| 816 static gfx::FontRenderParams params = GetGtkFontRenderParams(); | 817 static gfx::FontRenderParams params = GetGtkFontRenderParams(); |
| 817 return params; | 818 return params; |
| 818 } | 819 } |
| 819 | 820 |
| 820 void Gtk2UI::GetDefaultFontDescription( | 821 void Gtk2UI::GetDefaultFontDescription( |
| 821 std::string* family_out, | 822 std::string* family_out, |
| 822 int* size_pixels_out, | 823 int* size_pixels_out, |
| 823 int* style_out, | 824 bool* italic_out, |
| 825 gfx::Font::Weight* weight_out, |
| 824 gfx::FontRenderParams* params_out) const { | 826 gfx::FontRenderParams* params_out) const { |
| 825 *family_out = default_font_family_; | 827 *family_out = default_font_family_; |
| 826 *size_pixels_out = default_font_size_pixels_; | 828 *size_pixels_out = default_font_size_pixels_; |
| 827 *style_out = default_font_style_; | 829 *italic_out = (default_font_style_ & gfx::Font::ITALIC) != 0; |
| 830 *weight_out = default_font_weight_; |
| 828 *params_out = default_font_render_params_; | 831 *params_out = default_font_render_params_; |
| 829 } | 832 } |
| 830 | 833 |
| 831 ui::SelectFileDialog* Gtk2UI::CreateSelectFileDialog( | 834 ui::SelectFileDialog* Gtk2UI::CreateSelectFileDialog( |
| 832 ui::SelectFileDialog::Listener* listener, | 835 ui::SelectFileDialog::Listener* listener, |
| 833 ui::SelectFilePolicy* policy) const { | 836 ui::SelectFilePolicy* policy) const { |
| 834 return SelectFileDialogImpl::Create(listener, policy); | 837 return SelectFileDialogImpl::Create(listener, policy); |
| 835 } | 838 } |
| 836 | 839 |
| 837 bool Gtk2UI::UnityIsRunning() { | 840 bool Gtk2UI::UnityIsRunning() { |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1339 // Non-absolute sizes are in points (again scaled by PANGO_SIZE). | 1342 // Non-absolute sizes are in points (again scaled by PANGO_SIZE). |
| 1340 // Round the value when converting to pixels to match GTK's logic. | 1343 // Round the value when converting to pixels to match GTK's logic. |
| 1341 const double size_points = pango_font_description_get_size(desc) / | 1344 const double size_points = pango_font_description_get_size(desc) / |
| 1342 static_cast<double>(PANGO_SCALE); | 1345 static_cast<double>(PANGO_SCALE); |
| 1343 default_font_size_pixels_ = static_cast<int>( | 1346 default_font_size_pixels_ = static_cast<int>( |
| 1344 GetPixelsInPoint(device_scale_factor_) * size_points + 0.5); | 1347 GetPixelsInPoint(device_scale_factor_) * size_points + 0.5); |
| 1345 query.point_size = static_cast<int>(size_points); | 1348 query.point_size = static_cast<int>(size_points); |
| 1346 } | 1349 } |
| 1347 | 1350 |
| 1348 query.style = gfx::Font::NORMAL; | 1351 query.style = gfx::Font::NORMAL; |
| 1349 // TODO(davemoore): Support weights other than bold? | 1352 query.weight = |
| 1350 if (pango_font_description_get_weight(desc) == PANGO_WEIGHT_BOLD) | 1353 static_cast<gfx::Font::Weight>(pango_font_description_get_weight(desc)); |
| 1351 query.style |= gfx::Font::BOLD; | |
| 1352 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE? | 1354 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE? |
| 1353 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) | 1355 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) |
| 1354 query.style |= gfx::Font::ITALIC; | 1356 query.style |= gfx::Font::ITALIC; |
| 1355 | 1357 |
| 1356 default_font_render_params_ = | 1358 default_font_render_params_ = |
| 1357 gfx::GetFontRenderParams(query, &default_font_family_); | 1359 gfx::GetFontRenderParams(query, &default_font_family_); |
| 1358 default_font_style_ = query.style; | 1360 default_font_style_ = query.style; |
| 1359 } | 1361 } |
| 1360 | 1362 |
| 1361 void Gtk2UI::ResetStyle() { | 1363 void Gtk2UI::ResetStyle() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1378 // Blacklist scaling factors <130% (crbug.com/484400) and round | 1380 // Blacklist scaling factors <130% (crbug.com/484400) and round |
| 1379 // to 1 decimal to prevent rendering problems (crbug.com/485183). | 1381 // to 1 decimal to prevent rendering problems (crbug.com/485183). |
| 1380 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10; | 1382 return scale < 1.3f ? 1.0f : roundf(scale * 10) / 10; |
| 1381 } | 1383 } |
| 1382 | 1384 |
| 1383 } // namespace libgtk2ui | 1385 } // namespace libgtk2ui |
| 1384 | 1386 |
| 1385 views::LinuxUI* BuildGtk2UI() { | 1387 views::LinuxUI* BuildGtk2UI() { |
| 1386 return new libgtk2ui::Gtk2UI; | 1388 return new libgtk2ui::Gtk2UI; |
| 1387 } | 1389 } |
| OLD | NEW |