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 "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/environment.h" | 10 #include "base/environment.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 #if defined(USE_GCONF) | 44 #if defined(USE_GCONF) |
45 #include "chrome/browser/ui/libgtk2ui/gconf_titlebar_listener.h" | 45 #include "chrome/browser/ui/libgtk2ui/gconf_titlebar_listener.h" |
46 #endif | 46 #endif |
47 | 47 |
48 // A minimized port of GtkThemeService into something that can provide colors | 48 // A minimized port of GtkThemeService into something that can provide colors |
49 // and images for aura. | 49 // and images for aura. |
50 // | 50 // |
51 // TODO(erg): There's still a lot that needs ported or done for the first time: | 51 // TODO(erg): There's still a lot that needs ported or done for the first time: |
52 // | 52 // |
53 // - Render and inject the button overlay from the gtk theme. | |
54 // - Render and inject the omnibox background. | 53 // - Render and inject the omnibox background. |
55 // - Listen for the "style-set" signal on |fake_frame_| and recreate theme | 54 // - Listen for the "style-set" signal on |fake_frame_| and recreate theme |
56 // colors and images. | 55 // colors and images. |
57 // - Make sure to test with a light on dark theme, too. | 56 // - Make sure to test with a light on dark theme, too. |
58 // - Everything else that we're not doing. | 57 // - Everything else that we're not doing. |
59 | 58 |
60 namespace { | 59 namespace { |
61 | 60 |
62 struct GObjectDeleter { | 61 struct GObjectDeleter { |
63 void operator()(void* ptr) { | 62 void operator()(void* ptr) { |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 default: | 307 default: |
309 color_utils::HSL result = {-1, -1, -1}; | 308 color_utils::HSL result = {-1, -1, -1}; |
310 return result; | 309 return result; |
311 } | 310 } |
312 } | 311 } |
313 | 312 |
314 } // namespace | 313 } // namespace |
315 | 314 |
316 namespace libgtk2ui { | 315 namespace libgtk2ui { |
317 | 316 |
318 Gtk2UI::Gtk2UI() : use_gtk_(false) { | 317 Gtk2UI::Gtk2UI() { |
319 GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); | 318 GtkInitFromCommandLine(*CommandLine::ForCurrentProcess()); |
320 } | 319 } |
321 | 320 |
322 void Gtk2UI::Initialize() { | 321 void Gtk2UI::Initialize() { |
323 // Create our fake widgets. | 322 // Create our fake widgets. |
324 fake_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 323 fake_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
325 fake_frame_ = chrome_gtk_frame_new(); | 324 fake_frame_ = chrome_gtk_frame_new(); |
326 fake_label_.Own(gtk_label_new("")); | 325 fake_label_.Own(gtk_label_new("")); |
327 fake_entry_.Own(gtk_entry_new()); | 326 fake_entry_.Own(gtk_entry_new()); |
328 | 327 |
(...skipping 30 matching lines...) Expand all Loading... |
359 | 358 |
360 ClearAllThemeData(); | 359 ClearAllThemeData(); |
361 } | 360 } |
362 | 361 |
363 gfx::Image Gtk2UI::GetThemeImageNamed(int id) const { | 362 gfx::Image Gtk2UI::GetThemeImageNamed(int id) const { |
364 // Try to get our cached version: | 363 // Try to get our cached version: |
365 ImageCache::const_iterator it = gtk_images_.find(id); | 364 ImageCache::const_iterator it = gtk_images_.find(id); |
366 if (it != gtk_images_.end()) | 365 if (it != gtk_images_.end()) |
367 return it->second; | 366 return it->second; |
368 | 367 |
369 if (/*use_gtk_ && */ IsOverridableImage(id)) { | 368 if (IsOverridableImage(id)) { |
370 gfx::Image image = gfx::Image( | 369 gfx::Image image = gfx::Image( |
371 gfx::ImageSkia::CreateFrom1xBitmap(GenerateGtkThemeBitmap(id))); | 370 gfx::ImageSkia::CreateFrom1xBitmap(GenerateGtkThemeBitmap(id))); |
372 gtk_images_[id] = image; | 371 gtk_images_[id] = image; |
373 return image; | 372 return image; |
374 } | 373 } |
375 | 374 |
376 return gfx::Image(); | 375 return gfx::Image(); |
377 } | 376 } |
378 | 377 |
379 bool Gtk2UI::GetColor(int id, SkColor* color) const { | 378 bool Gtk2UI::GetColor(int id, SkColor* color) const { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 gint cursor_blink_time = kGtkDefaultCursorBlinkTime; | 435 gint cursor_blink_time = kGtkDefaultCursorBlinkTime; |
437 gboolean cursor_blink = TRUE; | 436 gboolean cursor_blink = TRUE; |
438 g_object_get(gtk_settings_get_default(), | 437 g_object_get(gtk_settings_get_default(), |
439 "gtk-cursor-blink-time", &cursor_blink_time, | 438 "gtk-cursor-blink-time", &cursor_blink_time, |
440 "gtk-cursor-blink", &cursor_blink, | 439 "gtk-cursor-blink", &cursor_blink, |
441 NULL); | 440 NULL); |
442 return cursor_blink ? (cursor_blink_time / kGtkCursorBlinkCycleFactor) : 0.0; | 441 return cursor_blink ? (cursor_blink_time / kGtkCursorBlinkCycleFactor) : 0.0; |
443 } | 442 } |
444 | 443 |
445 ui::NativeTheme* Gtk2UI::GetNativeTheme() const { | 444 ui::NativeTheme* Gtk2UI::GetNativeTheme() const { |
446 return use_gtk_ ? NativeThemeGtk2::instance() : | 445 return NativeThemeGtk2::instance(); |
447 ui::NativeTheme::instance(); | |
448 } | |
449 | |
450 void Gtk2UI::SetUseSystemTheme(bool use_system_theme) { | |
451 use_gtk_ = use_system_theme; | |
452 | |
453 FOR_EACH_OBSERVER(Gtk2Border, border_list_, | |
454 InvalidateAndSetUsesGtk(use_system_theme)); | |
455 } | |
456 | |
457 bool Gtk2UI::GetUseSystemTheme() const { | |
458 return use_gtk_; | |
459 } | 446 } |
460 | 447 |
461 bool Gtk2UI::GetDefaultUsesSystemTheme() const { | 448 bool Gtk2UI::GetDefaultUsesSystemTheme() const { |
462 scoped_ptr<base::Environment> env(base::Environment::Create()); | 449 scoped_ptr<base::Environment> env(base::Environment::Create()); |
463 | 450 |
464 switch (base::nix::GetDesktopEnvironment(env.get())) { | 451 switch (base::nix::GetDesktopEnvironment(env.get())) { |
465 case base::nix::DESKTOP_ENVIRONMENT_GNOME: | 452 case base::nix::DESKTOP_ENVIRONMENT_GNOME: |
466 case base::nix::DESKTOP_ENVIRONMENT_UNITY: | 453 case base::nix::DESKTOP_ENVIRONMENT_UNITY: |
467 case base::nix::DESKTOP_ENVIRONMENT_XFCE: | 454 case base::nix::DESKTOP_ENVIRONMENT_XFCE: |
468 return true; | 455 return true; |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1344 | 1331 |
1345 void Gtk2UI::ClearAllThemeData() { | 1332 void Gtk2UI::ClearAllThemeData() { |
1346 gtk_images_.clear(); | 1333 gtk_images_.clear(); |
1347 } | 1334 } |
1348 | 1335 |
1349 } // namespace libgtk2ui | 1336 } // namespace libgtk2ui |
1350 | 1337 |
1351 views::LinuxUI* BuildGtk2UI() { | 1338 views::LinuxUI* BuildGtk2UI() { |
1352 return new libgtk2ui::Gtk2UI; | 1339 return new libgtk2ui::Gtk2UI; |
1353 } | 1340 } |
OLD | NEW |