| 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 <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include <pango/pango.h> | 9 #include <pango/pango.h> |
| 10 | 10 |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 } | 374 } |
| 375 | 375 |
| 376 g_free(hint_style); | 376 g_free(hint_style); |
| 377 g_free(rgba); | 377 g_free(rgba); |
| 378 | 378 |
| 379 return params; | 379 return params; |
| 380 } | 380 } |
| 381 | 381 |
| 382 // Queries GTK for its font DPI setting and returns the number of pixels in a | 382 // Queries GTK for its font DPI setting and returns the number of pixels in a |
| 383 // point. | 383 // point. |
| 384 double GetPixelsInPoint() { | 384 double GetPixelsInPoint(float device_scale_factor) { |
| 385 GtkSettings* gtk_settings = gtk_settings_get_default(); | 385 GtkSettings* gtk_settings = gtk_settings_get_default(); |
| 386 CHECK(gtk_settings); | 386 CHECK(gtk_settings); |
| 387 gint gtk_dpi = -1; | 387 gint gtk_dpi = -1; |
| 388 g_object_get(gtk_settings, "gtk-xft-dpi", >k_dpi, NULL); | 388 g_object_get(gtk_settings, "gtk-xft-dpi", >k_dpi, NULL); |
| 389 | 389 |
| 390 // GTK multiplies the DPI by 1024 before storing it. | 390 // GTK multiplies the DPI by 1024 before storing it. |
| 391 double dpi = (gtk_dpi > 0) ? gtk_dpi / 1024.0 : 96.0; | 391 double dpi = (gtk_dpi > 0) ? gtk_dpi / 1024.0 : 96.0; |
| 392 | 392 |
| 393 // Take device_scale_factor into account — if Chrome already scales the |
| 394 // entire UI up by 2x, we should not also scale up. |
| 395 dpi /= device_scale_factor; |
| 396 |
| 393 // There are 72 points in an inch. | 397 // There are 72 points in an inch. |
| 394 return dpi / 72.0; | 398 return dpi / 72.0; |
| 395 } | 399 } |
| 396 | 400 |
| 397 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { | 401 views::LinuxUI::NonClientMiddleClickAction GetDefaultMiddleClickAction() { |
| 398 scoped_ptr<base::Environment> env(base::Environment::Create()); | 402 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 399 switch (base::nix::GetDesktopEnvironment(env.get())) { | 403 switch (base::nix::GetDesktopEnvironment(env.get())) { |
| 400 case base::nix::DESKTOP_ENVIRONMENT_KDE4: | 404 case base::nix::DESKTOP_ENVIRONMENT_KDE4: |
| 401 // Starting with KDE 4.4, windows' titlebars can be dragged with the | 405 // Starting with KDE 4.4, windows' titlebars can be dragged with the |
| 402 // middle mouse button to create tab groups. We don't support that in | 406 // middle mouse button to create tab groups. We don't support that in |
| 403 // Chrome, but at least avoid lowering windows in response to middle | 407 // Chrome, but at least avoid lowering windows in response to middle |
| 404 // clicks to avoid surprising users who expect the KDE behavior. | 408 // clicks to avoid surprising users who expect the KDE behavior. |
| 405 return views::LinuxUI::MIDDLE_CLICK_ACTION_NONE; | 409 return views::LinuxUI::MIDDLE_CLICK_ACTION_NONE; |
| 406 default: | 410 default: |
| 407 return views::LinuxUI::MIDDLE_CLICK_ACTION_LOWER; | 411 return views::LinuxUI::MIDDLE_CLICK_ACTION_LOWER; |
| 408 } | 412 } |
| 409 } | 413 } |
| 410 | 414 |
| 411 } // namespace | 415 } // namespace |
| 412 | 416 |
| 413 Gtk2UI::Gtk2UI() | 417 Gtk2UI::Gtk2UI() |
| 414 : default_font_size_pixels_(0), | 418 : default_font_size_pixels_(0), |
| 415 default_font_style_(gfx::Font::NORMAL), | 419 default_font_style_(gfx::Font::NORMAL), |
| 416 middle_click_action_(GetDefaultMiddleClickAction()) { | 420 middle_click_action_(GetDefaultMiddleClickAction()), |
| 421 device_scale_factor_(1.0) { |
| 417 GtkInitFromCommandLine(*base::CommandLine::ForCurrentProcess()); | 422 GtkInitFromCommandLine(*base::CommandLine::ForCurrentProcess()); |
| 418 } | 423 } |
| 419 | 424 |
| 420 void Gtk2UI::Initialize() { | 425 void Gtk2UI::Initialize() { |
| 421 signals_.reset(new Gtk2SignalRegistrar); | 426 signals_.reset(new Gtk2SignalRegistrar); |
| 422 | 427 |
| 423 // Create our fake widgets. | 428 // Create our fake widgets. |
| 424 fake_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 429 fake_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| 425 fake_frame_ = chrome_gtk_frame_new(); | 430 fake_frame_ = chrome_gtk_frame_new(); |
| 426 fake_label_.Own(gtk_label_new("")); | 431 fake_label_.Own(gtk_label_new("")); |
| (...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1377 // PANGO_SCALE Pango units in a device unit (pixel). | 1382 // PANGO_SCALE Pango units in a device unit (pixel). |
| 1378 const int size_pixels = pango_font_description_get_size(desc) / PANGO_SCALE; | 1383 const int size_pixels = pango_font_description_get_size(desc) / PANGO_SCALE; |
| 1379 default_font_size_pixels_ = size_pixels; | 1384 default_font_size_pixels_ = size_pixels; |
| 1380 query.pixel_size = size_pixels; | 1385 query.pixel_size = size_pixels; |
| 1381 } else { | 1386 } else { |
| 1382 // Non-absolute sizes are in points (again scaled by PANGO_SIZE). | 1387 // Non-absolute sizes are in points (again scaled by PANGO_SIZE). |
| 1383 // Round the value when converting to pixels to match GTK's logic. | 1388 // Round the value when converting to pixels to match GTK's logic. |
| 1384 const double size_points = pango_font_description_get_size(desc) / | 1389 const double size_points = pango_font_description_get_size(desc) / |
| 1385 static_cast<double>(PANGO_SCALE); | 1390 static_cast<double>(PANGO_SCALE); |
| 1386 default_font_size_pixels_ = static_cast<int>( | 1391 default_font_size_pixels_ = static_cast<int>( |
| 1387 GetPixelsInPoint() * size_points + 0.5); | 1392 GetPixelsInPoint(device_scale_factor_) * size_points + 0.5); |
| 1388 query.point_size = static_cast<int>(size_points); | 1393 query.point_size = static_cast<int>(size_points); |
| 1389 } | 1394 } |
| 1390 | 1395 |
| 1391 query.style = gfx::Font::NORMAL; | 1396 query.style = gfx::Font::NORMAL; |
| 1392 // TODO(davemoore): Support weights other than bold? | 1397 // TODO(davemoore): Support weights other than bold? |
| 1393 if (pango_font_description_get_weight(desc) == PANGO_WEIGHT_BOLD) | 1398 if (pango_font_description_get_weight(desc) == PANGO_WEIGHT_BOLD) |
| 1394 query.style |= gfx::Font::BOLD; | 1399 query.style |= gfx::Font::BOLD; |
| 1395 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE? | 1400 // TODO(davemoore): What about PANGO_STYLE_OBLIQUE? |
| 1396 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) | 1401 if (pango_font_description_get_style(desc) == PANGO_STYLE_ITALIC) |
| 1397 query.style |= gfx::Font::ITALIC; | 1402 query.style |= gfx::Font::ITALIC; |
| 1398 | 1403 |
| 1399 default_font_render_params_ = | 1404 default_font_render_params_ = |
| 1400 gfx::GetFontRenderParams(query, &default_font_family_); | 1405 gfx::GetFontRenderParams(query, &default_font_family_); |
| 1401 default_font_style_ = query.style; | 1406 default_font_style_ = query.style; |
| 1402 } | 1407 } |
| 1403 | 1408 |
| 1404 void Gtk2UI::OnStyleSet(GtkWidget* widget, GtkStyle* previous_style) { | 1409 void Gtk2UI::OnStyleSet(GtkWidget* widget, GtkStyle* previous_style) { |
| 1405 ClearAllThemeData(); | 1410 ClearAllThemeData(); |
| 1406 LoadGtkValues(); | 1411 LoadGtkValues(); |
| 1407 NativeThemeGtk2::instance()->NotifyObservers(); | 1412 NativeThemeGtk2::instance()->NotifyObservers(); |
| 1408 } | 1413 } |
| 1409 | 1414 |
| 1415 void Gtk2UI::UpdateDeviceScaleFactor(float device_scale_factor) { |
| 1416 device_scale_factor_ = device_scale_factor; |
| 1417 GtkStyle* label_style = gtk_rc_get_style(fake_label_.get()); |
| 1418 UpdateDefaultFont(label_style->font_desc); |
| 1419 } |
| 1420 |
| 1410 } // namespace libgtk2ui | 1421 } // namespace libgtk2ui |
| 1411 | 1422 |
| 1412 views::LinuxUI* BuildGtk2UI() { | 1423 views::LinuxUI* BuildGtk2UI() { |
| 1413 return new libgtk2ui::Gtk2UI; | 1424 return new libgtk2ui::Gtk2UI; |
| 1414 } | 1425 } |
| OLD | NEW |