OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/gtk/apps/native_app_window_gtk.h" | 5 #include "chrome/browser/ui/gtk/apps/native_app_window_gtk.h" |
6 | 6 |
7 #include <gdk/gdkx.h> | 7 #include <gdk/gdkx.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop/message_pump_gtk.h" | 10 #include "base/message_loop/message_pump_gtk.h" |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 bool NativeAppWindowGtk::IsAlwaysOnTop() const { | 345 bool NativeAppWindowGtk::IsAlwaysOnTop() const { |
346 return always_on_top_; | 346 return always_on_top_; |
347 } | 347 } |
348 | 348 |
349 void NativeAppWindowGtk::RenderViewHostChanged( | 349 void NativeAppWindowGtk::RenderViewHostChanged( |
350 content::RenderViewHost* old_host, | 350 content::RenderViewHost* old_host, |
351 content::RenderViewHost* new_host) { | 351 content::RenderViewHost* new_host) { |
352 web_contents()->GetView()->Focus(); | 352 web_contents()->GetView()->Focus(); |
353 } | 353 } |
354 | 354 |
355 gfx::Insets NativeAppWindowGtk::GetFrameInsets() const { | |
356 if (frameless_) | |
357 return gfx::Insets(); | |
358 GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(window_)); | |
359 if (!gdk_window) | |
360 return gfx::Insets(); | |
361 | |
362 gint current_width = 0; | |
363 gint current_height = 0; | |
364 gtk_window_get_size(window_, ¤t_width, ¤t_height); | |
365 gint current_x = 0; | |
366 gint current_y = 0; | |
367 gdk_window_get_position(gdk_window, ¤t_x, ¤t_y); | |
368 GdkRectangle rect_with_decorations = {0}; | |
369 gdk_window_get_frame_extents(gdk_window, | |
370 &rect_with_decorations); | |
371 | |
372 int left_inset = current_x - rect_with_decorations.x; | |
373 int top_inset = current_y - rect_with_decorations.y; | |
374 return gfx::Insets( | |
375 top_inset, | |
376 left_inset, | |
377 rect_with_decorations.height - current_height - top_inset, | |
378 rect_with_decorations.width - current_width - left_inset); | |
379 } | |
380 | |
381 bool NativeAppWindowGtk::IsVisible() const { | |
382 return gtk_widget_get_visible(GTK_WIDGET(window_)); | |
383 } | |
384 | |
385 void NativeAppWindowGtk::HideWithApp() {} | |
386 void NativeAppWindowGtk::ShowWithApp() {} | |
387 | |
388 void NativeAppWindowGtk::SetAlwaysOnTop(bool always_on_top) { | 355 void NativeAppWindowGtk::SetAlwaysOnTop(bool always_on_top) { |
389 if (always_on_top_ != always_on_top) { | 356 if (always_on_top_ != always_on_top) { |
390 // gdk_window_get_state() does not give us the correct value for the | 357 // gdk_window_get_state() does not give us the correct value for the |
391 // GDK_WINDOW_STATE_ABOVE bit. Cache the current state. | 358 // GDK_WINDOW_STATE_ABOVE bit. Cache the current state. |
392 always_on_top_ = always_on_top; | 359 always_on_top_ = always_on_top; |
393 gtk_window_set_keep_above(window_, always_on_top_ ? TRUE : FALSE); | 360 gtk_window_set_keep_above(window_, always_on_top_ ? TRUE : FALSE); |
394 shell_window_->OnNativeWindowChanged(); | 361 shell_window_->OnNativeWindowChanged(); |
395 } | 362 } |
396 } | 363 } |
397 | 364 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 gtk_util::SetWindowIcon(window_, profile, app_icon.ToGdkPixbuf()); | 610 gtk_util::SetWindowIcon(window_, profile, app_icon.ToGdkPixbuf()); |
644 else | 611 else |
645 gtk_util::SetWindowIcon(window_, profile); | 612 gtk_util::SetWindowIcon(window_, profile); |
646 } | 613 } |
647 | 614 |
648 void NativeAppWindowGtk::UpdateWindowTitle() { | 615 void NativeAppWindowGtk::UpdateWindowTitle() { |
649 string16 title = shell_window_->GetTitle(); | 616 string16 title = shell_window_->GetTitle(); |
650 gtk_window_set_title(window_, UTF16ToUTF8(title).c_str()); | 617 gtk_window_set_title(window_, UTF16ToUTF8(title).c_str()); |
651 } | 618 } |
652 | 619 |
653 void NativeAppWindowGtk::HandleKeyboardEvent( | |
654 const content::NativeWebKeyboardEvent& event) { | |
655 // No-op. | |
656 } | |
657 | |
658 void NativeAppWindowGtk::UpdateInputRegion(scoped_ptr<SkRegion> region) { | |
659 NOTIMPLEMENTED(); | |
660 } | |
661 | |
662 void NativeAppWindowGtk::UpdateDraggableRegions( | 620 void NativeAppWindowGtk::UpdateDraggableRegions( |
663 const std::vector<extensions::DraggableRegion>& regions) { | 621 const std::vector<extensions::DraggableRegion>& regions) { |
664 // Draggable region is not supported for non-frameless window. | 622 // Draggable region is not supported for non-frameless window. |
665 if (!frameless_) | 623 if (!frameless_) |
666 return; | 624 return; |
667 | 625 |
668 draggable_region_.reset(ShellWindow::RawDraggableRegionsToSkRegion(regions)); | 626 draggable_region_.reset(ShellWindow::RawDraggableRegionsToSkRegion(regions)); |
669 } | 627 } |
670 | 628 |
671 SkRegion* NativeAppWindowGtk::GetDraggableRegion() { | 629 SkRegion* NativeAppWindowGtk::GetDraggableRegion() { |
672 return draggable_region_.get(); | 630 return draggable_region_.get(); |
673 } | 631 } |
674 | 632 |
| 633 void NativeAppWindowGtk::UpdateInputRegion(scoped_ptr<SkRegion> region) { |
| 634 NOTIMPLEMENTED(); |
| 635 } |
| 636 |
| 637 void NativeAppWindowGtk::HandleKeyboardEvent( |
| 638 const content::NativeWebKeyboardEvent& event) { |
| 639 // No-op. |
| 640 } |
| 641 |
675 bool NativeAppWindowGtk::IsFrameless() const { | 642 bool NativeAppWindowGtk::IsFrameless() const { |
676 return frameless_; | 643 return frameless_; |
677 } | 644 } |
| 645 |
| 646 gfx::Insets NativeAppWindowGtk::GetFrameInsets() const { |
| 647 if (frameless_) |
| 648 return gfx::Insets(); |
| 649 GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(window_)); |
| 650 if (!gdk_window) |
| 651 return gfx::Insets(); |
| 652 |
| 653 gint current_width = 0; |
| 654 gint current_height = 0; |
| 655 gtk_window_get_size(window_, ¤t_width, ¤t_height); |
| 656 gint current_x = 0; |
| 657 gint current_y = 0; |
| 658 gdk_window_get_position(gdk_window, ¤t_x, ¤t_y); |
| 659 GdkRectangle rect_with_decorations = {0}; |
| 660 gdk_window_get_frame_extents(gdk_window, |
| 661 &rect_with_decorations); |
| 662 |
| 663 int left_inset = current_x - rect_with_decorations.x; |
| 664 int top_inset = current_y - rect_with_decorations.y; |
| 665 return gfx::Insets( |
| 666 top_inset, |
| 667 left_inset, |
| 668 rect_with_decorations.height - current_height - top_inset, |
| 669 rect_with_decorations.width - current_width - left_inset); |
| 670 } |
| 671 |
| 672 bool NativeAppWindowGtk::IsVisible() const { |
| 673 return gtk_widget_get_visible(GTK_WIDGET(window_)); |
| 674 } |
| 675 |
| 676 void NativeAppWindowGtk::HideWithApp() {} |
| 677 void NativeAppWindowGtk::ShowWithApp() {} |
OLD | NEW |