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/gtk/custom_button.h" | 10 #include "chrome/browser/ui/gtk/custom_button.h" |
11 #include "chrome/browser/ui/gtk/theme_service_gtk.h" | |
11 #include "chrome/browser/ui/panels/panel.h" | 12 #include "chrome/browser/ui/panels/panel.h" |
12 #include "chrome/browser/ui/panels/panel_bounds_animation.h" | 13 #include "chrome/browser/ui/panels/panel_bounds_animation.h" |
13 #include "chrome/browser/ui/panels/panel_browser_titlebar_gtk.h" | 14 #include "chrome/browser/ui/panels/panel_browser_titlebar_gtk.h" |
14 #include "chrome/browser/ui/panels/panel_drag_gtk.h" | 15 #include "chrome/browser/ui/panels/panel_drag_gtk.h" |
15 #include "chrome/browser/ui/panels/panel_manager.h" | 16 #include "chrome/browser/ui/panels/panel_manager.h" |
16 #include "chrome/browser/ui/panels/panel_strip.h" | 17 #include "chrome/browser/ui/panels/panel_strip.h" |
17 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
18 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
20 #include "grit/theme_resources_standard.h" | |
21 #include "third_party/skia/include/core/SkShader.h" | |
22 #include "ui/gfx/canvas.h" | |
23 #include "ui/gfx/image/cairo_cached_surface.h" | |
24 #include "ui/gfx/image/image.h" | |
25 #include "ui/gfx/skia_util.h" | |
19 | 26 |
20 using content::WebContents; | 27 using content::WebContents; |
21 | 28 |
22 namespace { | 29 namespace { |
23 | 30 |
24 // RGB values for titlebar in draw attention state. A shade of orange. | 31 // Colors used to draw active titlebar under default theme. |
jennb
2012/04/27 18:36:13
active titlebar and frame
jianli
2012/04/27 20:22:34
Done.
| |
25 const int kDrawAttentionR = 0xfa; | 32 const SkColor kActiveBackgroundDefaultColorStart = 0xfff0f8fa; |
dcheng
2012/04/27 01:18:39
Consider using SkColorSetARGB.
jianli
2012/04/27 20:22:34
Done.
| |
26 const int kDrawAttentionG = 0x98; | 33 const SkColor kActiveBackgroundDefaultColorEnd = 0xffc1d2dd; |
27 const int kDrawAttentionB = 0x3a; | |
28 const float kDrawAttentionRFraction = kDrawAttentionR / 255.0; | |
29 const float kDrawAttentionGFraction = kDrawAttentionG / 255.0; | |
30 const float kDrawAttentionBFraction = kDrawAttentionB / 255.0; | |
31 | 34 |
32 // Markup for title text in draw attention state. Set to color white. | 35 // Colors used to draw inactive titlebar under default theme. |
jennb
2012/04/27 18:36:13
titlebar and frame
jianli
2012/04/27 20:22:34
Done.
| |
33 const char* const kDrawAttentionTitleMarkupPrefix = | 36 const SkColor kInactiveBackgroundDefaultColorStart = 0xffffffff; |
34 "<span fgcolor='#ffffff'>"; | 37 const SkColor kInactiveBackgroundDefaultColorEnd = 0xffe7edf1; |
35 const char* const kDrawAttentionTitleMarkupSuffix = "</span>"; | 38 |
39 // Colors used to draw titlebar for drawing attention under default theme. | |
jennb
2012/04/27 18:36:13
titlebar and frame
jianli
2012/04/27 20:22:34
Done.
| |
40 // It is also used in non-default theme since attention color is not defined | |
41 // in the theme. | |
42 const SkColor kAttentionBackgroundDefaultColorStart = 0xffffab57; | |
43 const SkColor kAttentionBackgroundDefaultColorEnd = 0xffffab57; | |
36 | 44 |
37 // Set minimium width for window really small. | 45 // Set minimium width for window really small. |
38 const int kMinWindowWidth = 26; | 46 const int kMinWindowWidth = 26; |
39 | 47 |
48 gfx::Image* CreateGradientImage(SkColor start_color, SkColor end_color) { | |
49 // Though the height of titlebar, used for creating gradient, cannot be | |
50 // pre-determined, we use a reasonablly bigger value that should work for | |
51 // most of cases. | |
52 const int gradient_size = 32; | |
jennb
2012/04/27 18:36:13
How did you decide on this number?
jianli
2012/04/27 20:22:34
Added comment to explain this.
| |
53 SkShader* shader = gfx::CreateGradientShader( | |
54 0, gradient_size, start_color, end_color); | |
55 SkPaint paint; | |
56 paint.setStyle(SkPaint::kFill_Style); | |
57 paint.setAntiAlias(true); | |
58 paint.setShader(shader); | |
59 shader->unref(); | |
60 gfx::Canvas canvas(gfx::Size(1, gradient_size), true); | |
61 canvas.DrawRect(gfx::Rect(0, 0, 1, gradient_size), paint); | |
62 return new gfx::Image(new SkBitmap(canvas.ExtractBitmap())); | |
dcheng
2012/04/27 01:18:39
I think you can just do gfx::Image(canvas.ExtractB
jianli
2012/04/27 20:22:34
Done.
| |
63 } | |
64 | |
65 gfx::Image* GetActiveBackgroundDefaultImage() { | |
66 static gfx::Image* image = NULL; | |
67 if (!image) { | |
68 image = CreateGradientImage(kActiveBackgroundDefaultColorStart, | |
69 kActiveBackgroundDefaultColorEnd); | |
70 } | |
71 return image; | |
72 } | |
73 | |
74 gfx::Image* GetInactiveBackgroundDefaultImage() { | |
75 static gfx::Image* image = NULL; | |
76 if (!image) { | |
77 image = CreateGradientImage(kInactiveBackgroundDefaultColorStart, | |
78 kInactiveBackgroundDefaultColorEnd); | |
79 } | |
80 return image; | |
81 } | |
82 | |
83 gfx::Image* GetAttentionBackgroundDefaultImage() { | |
84 static gfx::Image* image = NULL; | |
85 if (!image) { | |
86 image = CreateGradientImage(kAttentionBackgroundDefaultColorStart, | |
87 kAttentionBackgroundDefaultColorEnd); | |
88 } | |
89 return image; | |
90 } | |
91 | |
40 } // namespace | 92 } // namespace |
41 | 93 |
42 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, | 94 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, |
43 const gfx::Rect& bounds) { | 95 const gfx::Rect& bounds) { |
44 PanelBrowserWindowGtk* panel_browser_window_gtk = | 96 PanelBrowserWindowGtk* panel_browser_window_gtk = |
45 new PanelBrowserWindowGtk(browser, panel, bounds); | 97 new PanelBrowserWindowGtk(browser, panel, bounds); |
46 panel_browser_window_gtk->Init(); | 98 panel_browser_window_gtk->Init(); |
47 return panel_browser_window_gtk; | 99 return panel_browser_window_gtk; |
48 } | 100 } |
49 | 101 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 registrar_.Add( | 133 registrar_.Add( |
82 this, | 134 this, |
83 chrome::NOTIFICATION_WINDOW_CLOSED, | 135 chrome::NOTIFICATION_WINDOW_CLOSED, |
84 content::Source<GtkWindow>(window())); | 136 content::Source<GtkWindow>(window())); |
85 } | 137 } |
86 | 138 |
87 BrowserTitlebar* PanelBrowserWindowGtk::CreateBrowserTitlebar() { | 139 BrowserTitlebar* PanelBrowserWindowGtk::CreateBrowserTitlebar() { |
88 return new PanelBrowserTitlebarGtk(this, window()); | 140 return new PanelBrowserTitlebarGtk(this, window()); |
89 } | 141 } |
90 | 142 |
143 PanelBrowserTitlebarGtk* PanelBrowserWindowGtk::GetTitlebar() const { | |
144 return static_cast<PanelBrowserTitlebarGtk*>(titlebar()); | |
145 } | |
146 | |
91 bool PanelBrowserWindowGtk::GetWindowEdge(int x, int y, GdkWindowEdge* edge) { | 147 bool PanelBrowserWindowGtk::GetWindowEdge(int x, int y, GdkWindowEdge* edge) { |
92 // Only detect the window edge when panels can be resized by the user. | 148 // Only detect the window edge when panels can be resized by the user. |
93 // This method is used by the base class to detect when the cursor has | 149 // This method is used by the base class to detect when the cursor has |
94 // hit the window edge in order to change the cursor to a resize cursor | 150 // hit the window edge in order to change the cursor to a resize cursor |
95 // and to detect when to initiate a resize drag. | 151 // and to detect when to initiate a resize drag. |
96 panel::Resizability resizability = panel_->CanResizeByMouse(); | 152 panel::Resizability resizability = panel_->CanResizeByMouse(); |
97 if (panel::NOT_RESIZABLE == resizability) | 153 if (panel::NOT_RESIZABLE == resizability) |
98 return false; | 154 return false; |
99 | 155 |
100 if (!BrowserWindowGtk::GetWindowEdge(x, y, edge)) | 156 if (!BrowserWindowGtk::GetWindowEdge(x, y, edge)) |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 window(), GTK_WIDGET(window()), &hints, GDK_HINT_MIN_SIZE); | 221 window(), GTK_WIDGET(window()), &hints, GDK_HINT_MIN_SIZE); |
166 | 222 |
167 DCHECK(frame_size_.IsEmpty()); | 223 DCHECK(frame_size_.IsEmpty()); |
168 } | 224 } |
169 | 225 |
170 void PanelBrowserWindowGtk::SetBounds(const gfx::Rect& bounds) { | 226 void PanelBrowserWindowGtk::SetBounds(const gfx::Rect& bounds) { |
171 // This should never be called. | 227 // This should never be called. |
172 DLOG(WARNING) << "Unexpected call to PanelBrowserWindowGtk::SetBounds()"; | 228 DLOG(WARNING) << "Unexpected call to PanelBrowserWindowGtk::SetBounds()"; |
173 } | 229 } |
174 | 230 |
231 bool PanelBrowserWindowGtk::IsMinimized() const { | |
jennb
2012/04/27 18:36:13
So confusing... Usually, Panel delegates to native
jianli
2012/04/27 20:22:34
Removed.
| |
232 return panel_->IsMinimized(); | |
233 } | |
234 | |
175 void PanelBrowserWindowGtk::OnSizeChanged(int width, int height) { | 235 void PanelBrowserWindowGtk::OnSizeChanged(int width, int height) { |
176 BrowserWindowGtk::OnSizeChanged(width, height); | 236 BrowserWindowGtk::OnSizeChanged(width, height); |
177 | 237 |
178 if (!frame_size_.IsEmpty()) | 238 if (!frame_size_.IsEmpty()) |
179 return; | 239 return; |
180 | 240 |
181 // The system is allowed to size the window before the desired panel | 241 // The system is allowed to size the window before the desired panel |
182 // bounds are applied. Save the frame size allocated by the system as | 242 // bounds are applied. Save the frame size allocated by the system as |
183 // it will be affected when we shrink the panel smaller than the frame. | 243 // it will be affected when we shrink the panel smaller than the frame. |
184 frame_size_ = GetNonClientFrameSize(); | 244 frame_size_ = GetNonClientFrameSize(); |
185 | 245 |
186 int top = bounds_.bottom() - height; | 246 int top = bounds_.bottom() - height; |
187 int left = bounds_.right() - width; | 247 int left = bounds_.right() - width; |
188 | 248 |
189 gtk_window_move(window_, left, top); | 249 gtk_window_move(window_, left, top); |
190 StartBoundsAnimation(gfx::Rect(left, top, width, height), bounds_); | 250 StartBoundsAnimation(gfx::Rect(left, top, width, height), bounds_); |
191 panel_->OnWindowSizeAvailable(); | 251 panel_->OnWindowSizeAvailable(); |
192 | 252 |
193 content::NotificationService::current()->Notify( | 253 content::NotificationService::current()->Notify( |
194 chrome::NOTIFICATION_PANEL_WINDOW_SIZE_KNOWN, | 254 chrome::NOTIFICATION_PANEL_WINDOW_SIZE_KNOWN, |
195 content::Source<Panel>(panel_.get()), | 255 content::Source<Panel>(panel_.get()), |
196 content::NotificationService::NoDetails()); | 256 content::NotificationService::NoDetails()); |
197 } | 257 } |
198 | 258 |
199 bool PanelBrowserWindowGtk::UseCustomFrame() { | 259 bool PanelBrowserWindowGtk::UseCustomFrame() { |
200 // We always use custom frame for panels. | 260 // We always use custom frame for panels. |
201 return TRUE; | 261 return true; |
262 } | |
263 | |
264 bool PanelBrowserWindowGtk::UsingCustomPopupFrame() const { | |
265 // We do not draw custom popup frame. | |
266 return false; | |
202 } | 267 } |
203 | 268 |
204 void PanelBrowserWindowGtk::DrawPopupFrame(cairo_t* cr, | 269 void PanelBrowserWindowGtk::DrawPopupFrame(cairo_t* cr, |
205 GtkWidget* widget, | 270 GtkWidget* widget, |
206 GdkEventExpose* event) { | 271 GdkEventExpose* event) { |
207 static_cast<PanelBrowserTitlebarGtk*>(titlebar())-> | 272 NOTREACHED(); |
208 UpdateMinimizeRestoreButtonVisibility(); | 273 } |
209 | 274 |
210 BrowserWindowGtk::DrawPopupFrame(cr, widget, event); | 275 const gfx::Image* PanelBrowserWindowGtk::GetFrameTheme() const { |
276 if (is_drawing_attention_) | |
277 return GetAttentionBackgroundDefaultImage(); | |
211 | 278 |
212 if (is_drawing_attention_) | 279 bool is_active = IsActive(); |
213 DrawAttentionFrame(cr, widget, event); | 280 ThemeServiceGtk* theme_provider = ThemeServiceGtk::GetFrom( |
281 browser()->profile()); | |
282 | |
283 if (theme_provider->UsingDefaultTheme()) { | |
284 return is_active ? GetActiveBackgroundDefaultImage() | |
285 : GetInactiveBackgroundDefaultImage(); | |
286 } | |
287 | |
288 return theme_provider->GetImageNamed( | |
289 is_active ? IDR_THEME_TOOLBAR : IDR_THEME_TAB_BACKGROUND); | |
214 } | 290 } |
215 | 291 |
216 void PanelBrowserWindowGtk::DrawCustomFrame(cairo_t* cr, | 292 void PanelBrowserWindowGtk::DrawCustomFrame(cairo_t* cr, |
217 GtkWidget* widget, | 293 GtkWidget* widget, |
218 GdkEventExpose* event) { | 294 GdkEventExpose* event) { |
219 static_cast<PanelBrowserTitlebarGtk*>(titlebar())-> | 295 GetTitlebar()->UpdateMinimizeRestoreButtonVisibility(); |
220 UpdateMinimizeRestoreButtonVisibility(); | |
221 | 296 |
222 BrowserWindowGtk::DrawCustomFrame(cr, widget, event); | 297 gfx::CairoCachedSurface* surface = GetFrameTheme()->ToCairo(); |
223 | 298 |
224 if (is_drawing_attention_) | 299 surface->SetSource(cr, widget, 0, 0); |
225 DrawAttentionFrame(cr, widget, event); | 300 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); |
226 } | 301 cairo_rectangle(cr, event->area.x, event->area.y, |
227 | 302 event->area.width, event->area.height); |
228 void PanelBrowserWindowGtk::DrawAttentionFrame(cairo_t* cr, | 303 cairo_fill(cr); |
229 GtkWidget* widget, | |
230 GdkEventExpose* event) { | |
231 cairo_set_source_rgb(cr, kDrawAttentionRFraction, | |
232 kDrawAttentionGFraction, | |
233 kDrawAttentionBFraction); | |
234 | |
235 GdkRectangle dest_rectangle = GetTitlebarRectForDrawAttention(); | |
236 GdkRegion* dest_region = gdk_region_rectangle(&dest_rectangle); | |
237 | |
238 gdk_region_intersect(dest_region, event->region); | |
239 gdk_cairo_region(cr, dest_region); | |
240 | |
241 cairo_clip(cr); | |
242 cairo_paint(cr); | |
243 gdk_region_destroy(dest_region); | |
244 } | 304 } |
245 | 305 |
246 void PanelBrowserWindowGtk::ActiveWindowChanged(GdkWindow* active_window) { | 306 void PanelBrowserWindowGtk::ActiveWindowChanged(GdkWindow* active_window) { |
247 bool was_active = IsActive(); | 307 bool was_active = IsActive(); |
248 BrowserWindowGtk::ActiveWindowChanged(active_window); | 308 BrowserWindowGtk::ActiveWindowChanged(active_window); |
249 bool is_active = IsActive(); | 309 bool is_active = IsActive(); |
250 if (!window() || was_active == is_active) // State didn't change. | 310 if (!window() || was_active == is_active) // State didn't change. |
251 return; | 311 return; |
252 | 312 |
253 panel_->OnActiveStateChanged(is_active); | 313 panel_->OnActiveStateChanged(is_active); |
254 } | 314 } |
255 | 315 |
256 BrowserWindowGtk::TitleDecoration PanelBrowserWindowGtk::GetWindowTitle( | |
257 std::string* title) const { | |
258 if (is_drawing_attention_) { | |
259 std::string title_original; | |
260 BrowserWindowGtk::TitleDecoration title_decoration = | |
261 BrowserWindowGtk::GetWindowTitle(&title_original); | |
262 DCHECK_EQ(BrowserWindowGtk::PLAIN_TEXT, title_decoration); | |
263 gchar* title_escaped = g_markup_escape_text(title_original.c_str(), -1); | |
264 gchar* title_with_markup = g_strconcat(kDrawAttentionTitleMarkupPrefix, | |
265 title_escaped, | |
266 kDrawAttentionTitleMarkupSuffix, | |
267 NULL); | |
268 *title = title_with_markup; | |
269 g_free(title_escaped); | |
270 g_free(title_with_markup); | |
271 return BrowserWindowGtk::PANGO_MARKUP; | |
272 } else { | |
273 return BrowserWindowGtk::GetWindowTitle(title); | |
274 } | |
275 } | |
276 | |
277 void PanelBrowserWindowGtk::Observe( | 316 void PanelBrowserWindowGtk::Observe( |
278 int type, | 317 int type, |
279 const content::NotificationSource& source, | 318 const content::NotificationSource& source, |
280 const content::NotificationDetails& details) { | 319 const content::NotificationDetails& details) { |
281 switch (type) { | 320 switch (type) { |
282 case chrome::NOTIFICATION_WINDOW_CLOSED: | 321 case chrome::NOTIFICATION_WINDOW_CLOSED: |
283 // Cleanup. | 322 // Cleanup. |
284 if (bounds_animator_.get()) | 323 if (bounds_animator_.get()) |
285 bounds_animator_.reset(); | 324 bounds_animator_.reset(); |
286 | 325 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 } | 443 } |
405 | 444 |
406 void PanelBrowserWindowGtk::DrawAttention(bool draw_attention) { | 445 void PanelBrowserWindowGtk::DrawAttention(bool draw_attention) { |
407 DCHECK((panel_->attention_mode() & Panel::USE_PANEL_ATTENTION) != 0); | 446 DCHECK((panel_->attention_mode() & Panel::USE_PANEL_ATTENTION) != 0); |
408 | 447 |
409 if (is_drawing_attention_ == draw_attention) | 448 if (is_drawing_attention_ == draw_attention) |
410 return; | 449 return; |
411 | 450 |
412 is_drawing_attention_ = draw_attention; | 451 is_drawing_attention_ = draw_attention; |
413 | 452 |
414 GdkRectangle rect = GetTitlebarRectForDrawAttention(); | 453 GetTitlebar()->UpdateTextColor(); |
415 gdk_window_invalidate_rect( | 454 UserChangedTheme(); |
jennb
2012/04/27 18:36:13
Seems like overkill. We just want to repaint the t
jianli
2012/04/27 20:22:34
Done.
| |
416 gtk_widget_get_window(GTK_WIDGET(window())), &rect, TRUE); | |
417 | |
418 UpdateTitleBar(); | |
419 | 455 |
420 if ((panel_->attention_mode() & Panel::USE_SYSTEM_ATTENTION) != 0) | 456 if ((panel_->attention_mode() & Panel::USE_SYSTEM_ATTENTION) != 0) |
421 ::BrowserWindowGtk::FlashFrame(draw_attention); | 457 ::BrowserWindowGtk::FlashFrame(draw_attention); |
422 } | 458 } |
423 | 459 |
424 bool PanelBrowserWindowGtk::IsDrawingAttention() const { | 460 bool PanelBrowserWindowGtk::IsDrawingAttention() const { |
425 return is_drawing_attention_; | 461 return is_drawing_attention_; |
426 } | 462 } |
427 | 463 |
428 bool PanelBrowserWindowGtk::PreHandlePanelKeyboardEvent( | 464 bool PanelBrowserWindowGtk::PreHandlePanelKeyboardEvent( |
(...skipping 13 matching lines...) Expand all Loading... | |
442 } | 478 } |
443 | 479 |
444 Browser* PanelBrowserWindowGtk::GetPanelBrowser() const { | 480 Browser* PanelBrowserWindowGtk::GetPanelBrowser() const { |
445 return browser(); | 481 return browser(); |
446 } | 482 } |
447 | 483 |
448 void PanelBrowserWindowGtk::DestroyPanelBrowser() { | 484 void PanelBrowserWindowGtk::DestroyPanelBrowser() { |
449 DestroyBrowser(); | 485 DestroyBrowser(); |
450 } | 486 } |
451 | 487 |
452 gfx::Size PanelBrowserWindowGtk::IconOnlySize() const { | 488 gfx::Size PanelBrowserWindowGtk::IconOnlySize() const { |
jennb
2012/04/27 18:36:13
go ahead and delete this obsoleted method in this
jianli
2012/04/27 20:22:34
Done.
| |
453 GtkAllocation allocation; | 489 return gfx::Size(); |
454 gtk_widget_get_allocation(titlebar_widget(), &allocation); | |
455 return gfx::Size(titlebar()->IconOnlyWidth(), allocation.height); | |
456 } | 490 } |
457 | 491 |
458 void PanelBrowserWindowGtk::EnsurePanelFullyVisible() { | 492 void PanelBrowserWindowGtk::EnsurePanelFullyVisible() { |
459 gtk_window_present(window()); | 493 gtk_window_present(window()); |
460 } | 494 } |
461 | 495 |
462 void PanelBrowserWindowGtk::SetPanelAppIconVisibility(bool visible) { | 496 void PanelBrowserWindowGtk::SetPanelAppIconVisibility(bool visible) { |
463 return; | 497 return; |
464 } | 498 } |
465 | 499 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
498 | 532 |
499 bounds_animator_->Start(); | 533 bounds_animator_->Start(); |
500 last_animation_progressed_bounds_ = animation_start_bounds_; | 534 last_animation_progressed_bounds_ = animation_start_bounds_; |
501 } | 535 } |
502 | 536 |
503 bool PanelBrowserWindowGtk::IsAnimatingBounds() const { | 537 bool PanelBrowserWindowGtk::IsAnimatingBounds() const { |
504 return bounds_animator_.get() && bounds_animator_->is_animating(); | 538 return bounds_animator_.get() && bounds_animator_->is_animating(); |
505 } | 539 } |
506 | 540 |
507 void PanelBrowserWindowGtk::AnimationEnded(const ui::Animation* animation) { | 541 void PanelBrowserWindowGtk::AnimationEnded(const ui::Animation* animation) { |
508 titlebar()->SendEnterNotifyToCloseButtonIfUnderMouse(); | 542 GetTitlebar()->SendEnterNotifyToCloseButtonIfUnderMouse(); |
509 panel_->manager()->OnPanelAnimationEnded(panel_.get()); | 543 panel_->manager()->OnPanelAnimationEnded(panel_.get()); |
510 } | 544 } |
511 | 545 |
512 void PanelBrowserWindowGtk::AnimationProgressed( | 546 void PanelBrowserWindowGtk::AnimationProgressed( |
513 const ui::Animation* animation) { | 547 const ui::Animation* animation) { |
514 DCHECK(!frame_size_.IsEmpty()); | 548 DCHECK(!frame_size_.IsEmpty()); |
515 | 549 |
516 gfx::Rect new_bounds = bounds_animator_->CurrentValueBetween( | 550 gfx::Rect new_bounds = bounds_animator_->CurrentValueBetween( |
517 animation_start_bounds_, bounds_); | 551 animation_start_bounds_, bounds_); |
518 | 552 |
519 gdk_window_move_resize(gtk_widget_get_window(GTK_WIDGET(window())), | 553 gdk_window_move_resize(gtk_widget_get_window(GTK_WIDGET(window())), |
520 new_bounds.x(), new_bounds.y(), | 554 new_bounds.x(), new_bounds.y(), |
521 new_bounds.width(), new_bounds.height()); | 555 new_bounds.width(), new_bounds.height()); |
522 | 556 |
523 last_animation_progressed_bounds_ = new_bounds; | 557 last_animation_progressed_bounds_ = new_bounds; |
524 } | 558 } |
525 | 559 |
526 GdkRectangle PanelBrowserWindowGtk::GetTitlebarRectForDrawAttention() const { | |
527 GdkRectangle rect; | |
528 rect.x = 0; | |
529 rect.y = 0; | |
530 // We get the window width and not the titlebar_widget() width because we'd | |
531 // like for the window borders on either side of the title bar to be the same | |
532 // color. | |
533 GtkAllocation window_allocation; | |
534 gtk_widget_get_allocation(GTK_WIDGET(window()), &window_allocation); | |
535 rect.width = window_allocation.width; | |
536 | |
537 GtkAllocation titlebar_allocation; | |
538 gtk_widget_get_allocation(titlebar_widget(), &titlebar_allocation); | |
539 rect.height = titlebar_allocation.height; | |
540 | |
541 return rect; | |
542 } | |
543 | |
544 gboolean PanelBrowserWindowGtk::OnTitlebarButtonReleaseEvent( | 560 gboolean PanelBrowserWindowGtk::OnTitlebarButtonReleaseEvent( |
545 GtkWidget* widget, GdkEventButton* event) { | 561 GtkWidget* widget, GdkEventButton* event) { |
546 if (event->button != 1) | 562 if (event->button != 1) |
547 return TRUE; | 563 return TRUE; |
548 | 564 |
549 panel_->OnTitlebarClicked((event->state & GDK_CONTROL_MASK) ? | 565 panel_->OnTitlebarClicked((event->state & GDK_CONTROL_MASK) ? |
550 panel::APPLY_TO_ALL : panel::NO_MODIFIER); | 566 panel::APPLY_TO_ALL : panel::NO_MODIFIER); |
551 return TRUE; | 567 return TRUE; |
552 } | 568 } |
553 | 569 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 } | 659 } |
644 | 660 |
645 void NativePanelTestingGtk::FinishDragTitlebar() { | 661 void NativePanelTestingGtk::FinishDragTitlebar() { |
646 if (!panel_browser_window_gtk_->drag_helper_.get()) | 662 if (!panel_browser_window_gtk_->drag_helper_.get()) |
647 return; | 663 return; |
648 | 664 |
649 panel_browser_window_gtk_->drag_helper_->EndDrag(false); | 665 panel_browser_window_gtk_->drag_helper_->EndDrag(false); |
650 } | 666 } |
651 | 667 |
652 bool NativePanelTestingGtk::VerifyDrawingAttention() const { | 668 bool NativePanelTestingGtk::VerifyDrawingAttention() const { |
653 std::string title; | 669 return panel_browser_window_gtk_->IsDrawingAttention(); |
654 BrowserWindowGtk::TitleDecoration decoration = | |
655 panel_browser_window_gtk_->GetWindowTitle(&title); | |
656 return panel_browser_window_gtk_->IsDrawingAttention() && | |
657 decoration == BrowserWindowGtk::PANGO_MARKUP; | |
658 } | 670 } |
659 | 671 |
660 bool NativePanelTestingGtk::VerifyActiveState(bool is_active) { | 672 bool NativePanelTestingGtk::VerifyActiveState(bool is_active) { |
661 // TODO(jianli): to be implemented. http://crbug.com/102737 | 673 // TODO(jianli): to be implemented. http://crbug.com/102737 |
662 return false; | 674 return false; |
663 } | 675 } |
664 | 676 |
665 void NativePanelTestingGtk::WaitForWindowCreationToComplete() const { | 677 void NativePanelTestingGtk::WaitForWindowCreationToComplete() const { |
666 while (panel_browser_window_gtk_->frame_size_.IsEmpty()) | 678 while (panel_browser_window_gtk_->frame_size_.IsEmpty()) |
667 MessageLoopForUI::current()->RunAllPending(); | 679 MessageLoopForUI::current()->RunAllPending(); |
668 while (panel_browser_window_gtk_->IsAnimatingBounds()) | 680 while (panel_browser_window_gtk_->IsAnimatingBounds()) |
669 MessageLoopForUI::current()->RunAllPending(); | 681 MessageLoopForUI::current()->RunAllPending(); |
670 } | 682 } |
671 | 683 |
672 bool NativePanelTestingGtk::IsWindowSizeKnown() const { | 684 bool NativePanelTestingGtk::IsWindowSizeKnown() const { |
673 return !panel_browser_window_gtk_->frame_size_.IsEmpty(); | 685 return !panel_browser_window_gtk_->frame_size_.IsEmpty(); |
674 } | 686 } |
675 | 687 |
676 bool NativePanelTestingGtk::IsAnimatingBounds() const { | 688 bool NativePanelTestingGtk::IsAnimatingBounds() const { |
677 return panel_browser_window_gtk_->IsAnimatingBounds(); | 689 return panel_browser_window_gtk_->IsAnimatingBounds(); |
678 } | 690 } |
679 | 691 |
680 bool NativePanelTestingGtk::IsButtonVisible( | 692 bool NativePanelTestingGtk::IsButtonVisible( |
681 TitlebarButtonType button_type) const { | 693 TitlebarButtonType button_type) const { |
682 PanelBrowserTitlebarGtk* titlebar = static_cast<PanelBrowserTitlebarGtk*>( | 694 PanelBrowserTitlebarGtk* titlebar = panel_browser_window_gtk_->GetTitlebar(); |
683 panel_browser_window_gtk_->titlebar()); | |
684 CustomDrawButton* button; | 695 CustomDrawButton* button; |
685 switch (button_type) { | 696 switch (button_type) { |
686 case CLOSE_BUTTON: | 697 case CLOSE_BUTTON: |
687 button = titlebar->close_button(); | 698 button = titlebar->close_button(); |
688 break; | 699 break; |
689 case MINIMIZE_BUTTON: | 700 case MINIMIZE_BUTTON: |
690 button = titlebar->minimize_button(); | 701 button = titlebar->minimize_button(); |
691 break; | 702 break; |
692 case RESTORE_BUTTON: | 703 case RESTORE_BUTTON: |
693 button = titlebar->unminimize_button(); | 704 button = titlebar->unminimize_button(); |
694 break; | 705 break; |
695 default: | 706 default: |
696 NOTREACHED(); | 707 NOTREACHED(); |
697 return false; | 708 return false; |
698 } | 709 } |
699 return gtk_widget_get_visible(button->widget()); | 710 return gtk_widget_get_visible(button->widget()); |
700 } | 711 } |
OLD | NEW |