| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/exo/shell_surface.h" | 5 #include "components/exo/shell_surface.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/frame/custom_frame_view_ash.h" | 9 #include "ash/frame/custom_frame_view_ash.h" |
| 10 #include "ash/public/cpp/shell_window_ids.h" | 10 #include "ash/public/cpp/shell_window_ids.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "ui/wm/core/shadow.h" | 41 #include "ui/wm/core/shadow.h" |
| 42 #include "ui/wm/core/shadow_controller.h" | 42 #include "ui/wm/core/shadow_controller.h" |
| 43 #include "ui/wm/core/shadow_types.h" | 43 #include "ui/wm/core/shadow_types.h" |
| 44 #include "ui/wm/core/window_animations.h" | 44 #include "ui/wm/core/window_animations.h" |
| 45 #include "ui/wm/core/window_util.h" | 45 #include "ui/wm/core/window_util.h" |
| 46 | 46 |
| 47 #if defined(OS_CHROMEOS) | 47 #if defined(OS_CHROMEOS) |
| 48 #include "chromeos/audio/chromeos_sounds.h" | 48 #include "chromeos/audio/chromeos_sounds.h" |
| 49 #endif | 49 #endif |
| 50 | 50 |
| 51 DECLARE_UI_CLASS_PROPERTY_TYPE(exo::ShellSurface*) |
| 52 |
| 51 namespace exo { | 53 namespace exo { |
| 52 namespace { | 54 namespace { |
| 53 | 55 |
| 54 // This is a struct for accelerator keys used to close ShellSurfaces. | 56 // This is a struct for accelerator keys used to close ShellSurfaces. |
| 55 const struct Accelerator { | 57 const struct Accelerator { |
| 56 ui::KeyboardCode keycode; | 58 ui::KeyboardCode keycode; |
| 57 int modifiers; | 59 int modifiers; |
| 58 } kCloseWindowAccelerators[] = { | 60 } kCloseWindowAccelerators[] = { |
| 59 {ui::VKEY_W, ui::EF_CONTROL_DOWN}, | 61 {ui::VKEY_W, ui::EF_CONTROL_DOWN}, |
| 60 {ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN}, | 62 {ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN}, |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 DCHECK_EQ(window->GetProperty(aura::client::kAnimationsDisabledKey), true); | 307 DCHECK_EQ(window->GetProperty(aura::client::kAnimationsDisabledKey), true); |
| 306 window->SetProperty(aura::client::kAnimationsDisabledKey, | 308 window->SetProperty(aura::client::kAnimationsDisabledKey, |
| 307 saved_animations_disabled_); | 309 saved_animations_disabled_); |
| 308 } | 310 } |
| 309 } | 311 } |
| 310 | 312 |
| 311 //////////////////////////////////////////////////////////////////////////////// | 313 //////////////////////////////////////////////////////////////////////////////// |
| 312 // ShellSurface, public: | 314 // ShellSurface, public: |
| 313 | 315 |
| 314 DEFINE_LOCAL_UI_CLASS_PROPERTY_KEY(Surface*, kMainSurfaceKey, nullptr) | 316 DEFINE_LOCAL_UI_CLASS_PROPERTY_KEY(Surface*, kMainSurfaceKey, nullptr) |
| 317 DEFINE_LOCAL_UI_CLASS_PROPERTY_KEY(ShellSurface*, kThisSurfaceKey, nullptr) |
| 315 | 318 |
| 316 ShellSurface::ShellSurface(Surface* surface, | 319 ShellSurface::ShellSurface(Surface* surface, |
| 317 ShellSurface* parent, | 320 ShellSurface* parent, |
| 318 BoundsMode bounds_mode, | 321 BoundsMode bounds_mode, |
| 319 const gfx::Point& origin, | 322 const gfx::Point& origin, |
| 320 bool activatable, | 323 bool activatable, |
| 321 bool can_minimize, | 324 bool can_minimize, |
| 322 int container) | 325 int container) |
| 323 : widget_(nullptr), | 326 : widget_(nullptr), |
| 324 surface_(surface), | 327 surface_(surface), |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 .app_id; | 568 .app_id; |
| 566 } | 569 } |
| 567 | 570 |
| 568 void ShellSurface::SetApplicationId(const std::string& application_id) { | 571 void ShellSurface::SetApplicationId(const std::string& application_id) { |
| 569 // Store the value in |application_id_| in case the window does not exist yet. | 572 // Store the value in |application_id_| in case the window does not exist yet. |
| 570 application_id_ = application_id; | 573 application_id_ = application_id; |
| 571 if (widget_ && widget_->GetNativeWindow()) | 574 if (widget_ && widget_->GetNativeWindow()) |
| 572 SetApplicationId(widget_->GetNativeWindow(), application_id); | 575 SetApplicationId(widget_->GetNativeWindow(), application_id); |
| 573 } | 576 } |
| 574 | 577 |
| 578 // static |
| 579 void ShellSurface::SetAppIcon(aura::Window* window, |
| 580 const gfx::ImageSkia& icon) { |
| 581 DCHECK(!GetApplicationId(window).empty()); |
| 582 ShellSurface* this_surface = window->GetProperty(kThisSurfaceKey); |
| 583 if (this_surface) { |
| 584 this_surface->icon_ = icon; |
| 585 this_surface->widget_->UpdateWindowIcon(); |
| 586 } else { |
| 587 // Support unit test case. |
| 588 window->SetProperty(aura::client::kAppIconKey, new gfx::ImageSkia(icon)); |
| 589 } |
| 590 } |
| 591 |
| 575 void ShellSurface::Move() { | 592 void ShellSurface::Move() { |
| 576 TRACE_EVENT0("exo", "ShellSurface::Move"); | 593 TRACE_EVENT0("exo", "ShellSurface::Move"); |
| 577 | 594 |
| 578 if (!widget_) | 595 if (!widget_) |
| 579 return; | 596 return; |
| 580 | 597 |
| 581 switch (bounds_mode_) { | 598 switch (bounds_mode_) { |
| 582 case BoundsMode::SHELL: | 599 case BoundsMode::SHELL: |
| 583 case BoundsMode::CLIENT: | 600 case BoundsMode::CLIENT: |
| 584 AttemptToStartDrag(HTCAPTION); | 601 AttemptToStartDrag(HTCAPTION); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 } | 867 } |
| 851 | 868 |
| 852 bool ShellSurface::CanMinimize() const { | 869 bool ShellSurface::CanMinimize() const { |
| 853 return can_minimize_; | 870 return can_minimize_; |
| 854 } | 871 } |
| 855 | 872 |
| 856 base::string16 ShellSurface::GetWindowTitle() const { | 873 base::string16 ShellSurface::GetWindowTitle() const { |
| 857 return title_; | 874 return title_; |
| 858 } | 875 } |
| 859 | 876 |
| 877 gfx::ImageSkia ShellSurface::GetWindowIcon() { |
| 878 return icon_; |
| 879 } |
| 880 |
| 860 void ShellSurface::SaveWindowPlacement(const gfx::Rect& bounds, | 881 void ShellSurface::SaveWindowPlacement(const gfx::Rect& bounds, |
| 861 ui::WindowShowState show_state) { | 882 ui::WindowShowState show_state) { |
| 862 if (bounds_mode_ != BoundsMode::CLIENT) | 883 if (bounds_mode_ != BoundsMode::CLIENT) |
| 863 WidgetDelegate::SaveWindowPlacement(bounds, show_state); | 884 WidgetDelegate::SaveWindowPlacement(bounds, show_state); |
| 864 } | 885 } |
| 865 | 886 |
| 866 bool ShellSurface::GetSavedWindowPlacement( | 887 bool ShellSurface::GetSavedWindowPlacement( |
| 867 const views::Widget* widget, | 888 const views::Widget* widget, |
| 868 gfx::Rect* bounds, | 889 gfx::Rect* bounds, |
| 869 ui::WindowShowState* show_state) const { | 890 ui::WindowShowState* show_state) const { |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 widget_->Init(params); | 1215 widget_->Init(params); |
| 1195 | 1216 |
| 1196 aura::Window* window = widget_->GetNativeWindow(); | 1217 aura::Window* window = widget_->GetNativeWindow(); |
| 1197 window->SetName("ExoShellSurface"); | 1218 window->SetName("ExoShellSurface"); |
| 1198 window->SetProperty(aura::client::kAccessibilityFocusFallsbackToWidgetKey, | 1219 window->SetProperty(aura::client::kAccessibilityFocusFallsbackToWidgetKey, |
| 1199 false); | 1220 false); |
| 1200 window->AddChild(surface_->window()); | 1221 window->AddChild(surface_->window()); |
| 1201 window->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter(widget_))); | 1222 window->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter(widget_))); |
| 1202 SetApplicationId(window, application_id_); | 1223 SetApplicationId(window, application_id_); |
| 1203 SetMainSurface(window, surface_); | 1224 SetMainSurface(window, surface_); |
| 1225 window->SetProperty(kThisSurfaceKey, this); |
| 1204 | 1226 |
| 1205 // Start tracking changes to window bounds and window state. | 1227 // Start tracking changes to window bounds and window state. |
| 1206 window->AddObserver(this); | 1228 window->AddObserver(this); |
| 1207 ash::wm::WindowState* window_state = ash::wm::GetWindowState(window); | 1229 ash::wm::WindowState* window_state = ash::wm::GetWindowState(window); |
| 1208 window_state->AddObserver(this); | 1230 window_state->AddObserver(this); |
| 1209 | 1231 |
| 1210 // Allow the client to request bounds that do not fill the entire work area | 1232 // Allow the client to request bounds that do not fill the entire work area |
| 1211 // when maximized, or the entire display when fullscreen. | 1233 // when maximized, or the entire display when fullscreen. |
| 1212 window_state->set_allow_set_bounds_direct(bounds_mode_ == BoundsMode::CLIENT); | 1234 window_state->set_allow_set_bounds_direct(bounds_mode_ == BoundsMode::CLIENT); |
| 1213 | 1235 |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1737 gfx::Point ShellSurface::GetMouseLocation() const { | 1759 gfx::Point ShellSurface::GetMouseLocation() const { |
| 1738 aura::Window* const root_window = widget_->GetNativeWindow()->GetRootWindow(); | 1760 aura::Window* const root_window = widget_->GetNativeWindow()->GetRootWindow(); |
| 1739 gfx::Point location = | 1761 gfx::Point location = |
| 1740 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot(); | 1762 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot(); |
| 1741 aura::Window::ConvertPointToTarget( | 1763 aura::Window::ConvertPointToTarget( |
| 1742 root_window, widget_->GetNativeWindow()->parent(), &location); | 1764 root_window, widget_->GetNativeWindow()->parent(), &location); |
| 1743 return location; | 1765 return location; |
| 1744 } | 1766 } |
| 1745 | 1767 |
| 1746 } // namespace exo | 1768 } // namespace exo |
| OLD | NEW |