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/panels/panel_browser_window_gtk.h" | 5 #include "chrome/browser/ui/panels/panel_browser_window_gtk.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/browser/ui/browser_list.h" | 8 #include "chrome/browser/ui/browser_list.h" |
9 #include "chrome/browser/ui/gtk/browser_titlebar.h" | 9 #include "chrome/browser/ui/gtk/browser_titlebar.h" |
10 #include "chrome/browser/ui/panels/panel.h" | 10 #include "chrome/browser/ui/panels/panel.h" |
11 #include "chrome/browser/ui/panels/panel_bounds_animation.h" | 11 #include "chrome/browser/ui/panels/panel_bounds_animation.h" |
12 #include "chrome/browser/ui/panels/panel_drag_gtk.h" | 12 #include "chrome/browser/ui/panels/panel_drag_gtk.h" |
13 #include "chrome/browser/ui/panels/panel_manager.h" | 13 #include "chrome/browser/ui/panels/panel_manager.h" |
14 #include "chrome/browser/ui/panels/panel_strip.h" | 14 #include "chrome/browser/ui/panels/panel_strip.h" |
15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
17 | 17 |
18 using content::WebContents; | 18 using content::WebContents; |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // RGB values for titlebar in draw attention state. A shade of orange. | 22 // RGB values for titlebar in draw attention state. A shade of orange. |
23 const int kDrawAttentionR = 0xfa; | 23 const int kDrawAttentionR = 0xfa; |
24 const int kDrawAttentionG = 0x98; | 24 const int kDrawAttentionG = 0x98; |
25 const int kDrawAttentionB = 0x3a; | 25 const int kDrawAttentionB = 0x3a; |
26 const float kDrawAttentionRFraction = kDrawAttentionR / 255.0; | 26 const float kDrawAttentionRFraction = kDrawAttentionR / 255.0; |
27 const float kDrawAttentionGFraction = kDrawAttentionG / 255.0; | 27 const float kDrawAttentionGFraction = kDrawAttentionG / 255.0; |
28 const float kDrawAttentionBFraction = kDrawAttentionB / 255.0; | 28 const float kDrawAttentionBFraction = kDrawAttentionB / 255.0; |
29 | 29 |
30 // Delay before click on a titlebar is allowed to minimize the panel after | |
31 // the 'draw attention' mode has been cleared. | |
32 const int kSuspendMinimizeOnClickIntervalMs = 500; | |
33 | |
34 // Markup for title text in draw attention state. Set to color white. | 30 // Markup for title text in draw attention state. Set to color white. |
35 const char* const kDrawAttentionTitleMarkupPrefix = | 31 const char* const kDrawAttentionTitleMarkupPrefix = |
36 "<span fgcolor='#ffffff'>"; | 32 "<span fgcolor='#ffffff'>"; |
37 const char* const kDrawAttentionTitleMarkupSuffix = "</span>"; | 33 const char* const kDrawAttentionTitleMarkupSuffix = "</span>"; |
38 | 34 |
39 // Set minimium width for window really small. | 35 // Set minimium width for window really small. |
40 const int kMinWindowWidth = 26; | 36 const int kMinWindowWidth = 26; |
41 | 37 |
42 } // namespace | 38 } // namespace |
43 | 39 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 gdk_cairo_region(cr, dest_region); | 231 gdk_cairo_region(cr, dest_region); |
236 | 232 |
237 cairo_clip(cr); | 233 cairo_clip(cr); |
238 cairo_paint(cr); | 234 cairo_paint(cr); |
239 gdk_region_destroy(dest_region); | 235 gdk_region_destroy(dest_region); |
240 } | 236 } |
241 | 237 |
242 void PanelBrowserWindowGtk::ActiveWindowChanged(GdkWindow* active_window) { | 238 void PanelBrowserWindowGtk::ActiveWindowChanged(GdkWindow* active_window) { |
243 bool was_active = IsActive(); | 239 bool was_active = IsActive(); |
244 BrowserWindowGtk::ActiveWindowChanged(active_window); | 240 BrowserWindowGtk::ActiveWindowChanged(active_window); |
245 if (!window() || was_active == IsActive()) // State didn't change. | 241 bool is_active = IsActive(); |
| 242 if (!window() || was_active == is_active) // State didn't change. |
246 return; | 243 return; |
247 | 244 |
248 content::NotificationService::current()->Notify( | 245 panel_->OnActiveStateChanged(is_active); |
249 chrome::NOTIFICATION_PANEL_CHANGED_ACTIVE_STATUS, | |
250 content::Source<Panel>(panel_.get()), | |
251 content::NotificationService::NoDetails()); | |
252 panel_->OnActiveStateChanged(); | |
253 } | 246 } |
254 | 247 |
255 BrowserWindowGtk::TitleDecoration PanelBrowserWindowGtk::GetWindowTitle( | 248 BrowserWindowGtk::TitleDecoration PanelBrowserWindowGtk::GetWindowTitle( |
256 std::string* title) const { | 249 std::string* title) const { |
257 if (is_drawing_attention_) { | 250 if (is_drawing_attention_) { |
258 std::string title_original; | 251 std::string title_original; |
259 BrowserWindowGtk::TitleDecoration title_decoration = | 252 BrowserWindowGtk::TitleDecoration title_decoration = |
260 BrowserWindowGtk::GetWindowTitle(&title_original); | 253 BrowserWindowGtk::GetWindowTitle(&title_original); |
261 DCHECK_EQ(BrowserWindowGtk::PLAIN_TEXT, title_decoration); | 254 DCHECK_EQ(BrowserWindowGtk::PLAIN_TEXT, title_decoration); |
262 gchar* title_escaped = g_markup_escape_text(title_original.c_str(), -1); | 255 gchar* title_escaped = g_markup_escape_text(title_original.c_str(), -1); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 rect.height = titlebar_allocation.height; | 556 rect.height = titlebar_allocation.height; |
564 | 557 |
565 return rect; | 558 return rect; |
566 } | 559 } |
567 | 560 |
568 gboolean PanelBrowserWindowGtk::OnTitlebarButtonReleaseEvent( | 561 gboolean PanelBrowserWindowGtk::OnTitlebarButtonReleaseEvent( |
569 GtkWidget* widget, GdkEventButton* event) { | 562 GtkWidget* widget, GdkEventButton* event) { |
570 if (event->button != 1) | 563 if (event->button != 1) |
571 return TRUE; | 564 return TRUE; |
572 | 565 |
573 if (event->state & GDK_CONTROL_MASK) { | 566 panel_->OnTitlebarClicked((event->state & GDK_CONTROL_MASK) ? |
574 panel_->OnTitlebarClicked(panel::APPLY_TO_ALL); | 567 panel::APPLY_TO_ALL : panel::NO_MODIFIER); |
575 return TRUE; | |
576 } | |
577 | |
578 // TODO(jennb): Move remaining titlebar click handling out of here. | |
579 // (http://crbug.com/118431) | |
580 PanelStrip* panel_strip = panel_->panel_strip(); | |
581 if (!panel_strip) | |
582 return TRUE; | |
583 | |
584 if (panel_strip->type() == PanelStrip::DOCKED && | |
585 panel_->expansion_state() == Panel::EXPANDED) { | |
586 if (base::Time::Now() < disableMinimizeUntilTime_) | |
587 return TRUE; | |
588 | |
589 panel_->SetExpansionState(Panel::MINIMIZED); | |
590 } else { | |
591 panel_->Activate(); | |
592 } | |
593 | |
594 return TRUE; | 568 return TRUE; |
595 } | 569 } |
596 | 570 |
597 void PanelBrowserWindowGtk::HandleFocusIn(GtkWidget* widget, | |
598 GdkEventFocus* event) { | |
599 BrowserWindowGtk::HandleFocusIn(widget, event); | |
600 | |
601 // Do not clear draw attention if user cannot see contents of panel. | |
602 if (!is_drawing_attention_ || panel_->IsMinimized()) | |
603 return; | |
604 | |
605 panel_->FlashFrame(false); | |
606 | |
607 disableMinimizeUntilTime_ = base::Time::Now() + | |
608 base::TimeDelta::FromMilliseconds(kSuspendMinimizeOnClickIntervalMs); | |
609 } | |
610 | |
611 // NativePanelTesting implementation. | 571 // NativePanelTesting implementation. |
612 class NativePanelTestingGtk : public NativePanelTesting { | 572 class NativePanelTestingGtk : public NativePanelTesting { |
613 public: | 573 public: |
614 explicit NativePanelTestingGtk( | 574 explicit NativePanelTestingGtk( |
615 PanelBrowserWindowGtk* panel_browser_window_gtk); | 575 PanelBrowserWindowGtk* panel_browser_window_gtk); |
616 | 576 |
617 private: | 577 private: |
618 virtual void PressLeftMouseButtonTitlebar( | 578 virtual void PressLeftMouseButtonTitlebar( |
619 const gfx::Point& mouse_location, panel::ClickModifier modifier) OVERRIDE; | 579 const gfx::Point& mouse_location, panel::ClickModifier modifier) OVERRIDE; |
620 virtual void ReleaseMouseButtonTitlebar( | 580 virtual void ReleaseMouseButtonTitlebar( |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 MessageLoopForUI::current()->RunAllPending(); | 685 MessageLoopForUI::current()->RunAllPending(); |
726 } | 686 } |
727 | 687 |
728 bool NativePanelTestingGtk::IsWindowSizeKnown() const { | 688 bool NativePanelTestingGtk::IsWindowSizeKnown() const { |
729 return !panel_browser_window_gtk_->frame_size_.IsEmpty(); | 689 return !panel_browser_window_gtk_->frame_size_.IsEmpty(); |
730 } | 690 } |
731 | 691 |
732 bool NativePanelTestingGtk::IsAnimatingBounds() const { | 692 bool NativePanelTestingGtk::IsAnimatingBounds() const { |
733 return panel_browser_window_gtk_->IsAnimatingBounds(); | 693 return panel_browser_window_gtk_->IsAnimatingBounds(); |
734 } | 694 } |
OLD | NEW |