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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 // This is a struct for accelerator keys used to close ShellSurfaces. | 54 // This is a struct for accelerator keys used to close ShellSurfaces. |
55 const struct Accelerator { | 55 const struct Accelerator { |
56 ui::KeyboardCode keycode; | 56 ui::KeyboardCode keycode; |
57 int modifiers; | 57 int modifiers; |
58 } kCloseWindowAccelerators[] = { | 58 } kCloseWindowAccelerators[] = { |
59 {ui::VKEY_W, ui::EF_CONTROL_DOWN}, | 59 {ui::VKEY_W, ui::EF_CONTROL_DOWN}, |
60 {ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN}, | 60 {ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN}, |
61 {ui::VKEY_F4, ui::EF_ALT_DOWN}}; | 61 {ui::VKEY_F4, ui::EF_ALT_DOWN}}; |
62 | 62 |
| 63 constexpr uint32_t kFirstIconChunkFlag = 0x1; |
| 64 constexpr uint32_t kLastIconChunkFlag = 0x2; |
| 65 constexpr size_t kMaxIconSize = 32 * 1024; |
| 66 |
63 class CustomFrameView : public views::NonClientFrameView { | 67 class CustomFrameView : public views::NonClientFrameView { |
64 public: | 68 public: |
65 explicit CustomFrameView(views::Widget* widget) : widget_(widget) {} | 69 explicit CustomFrameView(views::Widget* widget) : widget_(widget) {} |
66 ~CustomFrameView() override {} | 70 ~CustomFrameView() override {} |
67 | 71 |
68 // Overridden from views::NonClientFrameView: | 72 // Overridden from views::NonClientFrameView: |
69 gfx::Rect GetBoundsForClientView() const override { return bounds(); } | 73 gfx::Rect GetBoundsForClientView() const override { return bounds(); } |
70 gfx::Rect GetWindowBoundsForClientBounds( | 74 gfx::Rect GetWindowBoundsForClientBounds( |
71 const gfx::Rect& client_bounds) const override { | 75 const gfx::Rect& client_bounds) const override { |
72 return client_bounds; | 76 return client_bounds; |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 DCHECK_EQ(window->GetProperty(aura::client::kAnimationsDisabledKey), true); | 309 DCHECK_EQ(window->GetProperty(aura::client::kAnimationsDisabledKey), true); |
306 window->SetProperty(aura::client::kAnimationsDisabledKey, | 310 window->SetProperty(aura::client::kAnimationsDisabledKey, |
307 saved_animations_disabled_); | 311 saved_animations_disabled_); |
308 } | 312 } |
309 } | 313 } |
310 | 314 |
311 //////////////////////////////////////////////////////////////////////////////// | 315 //////////////////////////////////////////////////////////////////////////////// |
312 // ShellSurface, public: | 316 // ShellSurface, public: |
313 | 317 |
314 DEFINE_LOCAL_UI_CLASS_PROPERTY_KEY(Surface*, kMainSurfaceKey, nullptr) | 318 DEFINE_LOCAL_UI_CLASS_PROPERTY_KEY(Surface*, kMainSurfaceKey, nullptr) |
| 319 DEFINE_LOCAL_UI_CLASS_PROPERTY_KEY(std::string*, kUnsafeIconPngDataKey, nullptr) |
315 | 320 |
316 ShellSurface::ShellSurface(Surface* surface, | 321 ShellSurface::ShellSurface(Surface* surface, |
317 ShellSurface* parent, | 322 ShellSurface* parent, |
318 BoundsMode bounds_mode, | 323 BoundsMode bounds_mode, |
319 const gfx::Point& origin, | 324 const gfx::Point& origin, |
320 bool activatable, | 325 bool activatable, |
321 bool can_minimize, | 326 bool can_minimize, |
322 int container) | 327 int container) |
323 : widget_(nullptr), | 328 : widget_(nullptr), |
324 surface_(surface), | 329 surface_(surface), |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 | 519 |
515 void ShellSurface::SetTitle(const base::string16& title) { | 520 void ShellSurface::SetTitle(const base::string16& title) { |
516 TRACE_EVENT1("exo", "ShellSurface::SetTitle", "title", | 521 TRACE_EVENT1("exo", "ShellSurface::SetTitle", "title", |
517 base::UTF16ToUTF8(title)); | 522 base::UTF16ToUTF8(title)); |
518 | 523 |
519 title_ = title; | 524 title_ = title; |
520 if (widget_) | 525 if (widget_) |
521 widget_->UpdateWindowTitle(); | 526 widget_->UpdateWindowTitle(); |
522 } | 527 } |
523 | 528 |
| 529 void ShellSurface::SetIconChunk(uint32_t flags, |
| 530 const std::string& unsafe_icon_png) { |
| 531 TRACE_EVENT0("exo", "ShellSurface::SetIconChunk"); |
| 532 |
| 533 if (flags & kFirstIconChunkFlag) { |
| 534 unsafe_icon_png_builder_.clear(); |
| 535 } else if (unsafe_icon_png_builder_.empty()) { |
| 536 LOG(ERROR) << "Received shelf icon chunk withot first chunk."; |
| 537 return; |
| 538 } |
| 539 |
| 540 if (unsafe_icon_png.size() + unsafe_icon_png_builder_.size() > kMaxIconSize) { |
| 541 unsafe_icon_png_builder_.clear(); |
| 542 LOG(WARNING) << "Surface icon is too big " |
| 543 << (unsafe_icon_png.size() + unsafe_icon_png_builder_.size()) |
| 544 << "."; |
| 545 return; |
| 546 } |
| 547 |
| 548 unsafe_icon_png_builder_ += unsafe_icon_png; |
| 549 if (flags & kLastIconChunkFlag) { |
| 550 unsafe_icon_png_ = unsafe_icon_png_builder_; |
| 551 unsafe_icon_png_builder_.clear(); |
| 552 if (widget_ && widget_->GetNativeWindow()) |
| 553 SetUnsafeIconPngData(widget_->GetNativeWindow(), &unsafe_icon_png_); |
| 554 } |
| 555 } |
| 556 |
| 557 void ShellSurface::ResetIcon() { |
| 558 unsafe_icon_png_.clear(); |
| 559 unsafe_icon_png_builder_.clear(); |
| 560 if (widget_ && widget_->GetNativeWindow()) |
| 561 SetUnsafeIconPngData(widget_->GetNativeWindow(), nullptr); |
| 562 } |
| 563 |
524 void ShellSurface::SetSystemModal(bool system_modal) { | 564 void ShellSurface::SetSystemModal(bool system_modal) { |
525 // System modal container is used by clients to implement client side | 565 // System modal container is used by clients to implement client side |
526 // managed system modal dialogs using a single ShellSurface instance. | 566 // managed system modal dialogs using a single ShellSurface instance. |
527 // Hit-test region will be non-empty when at least one dialog exists on | 567 // Hit-test region will be non-empty when at least one dialog exists on |
528 // the client side. Here we detect the transition between no client side | 568 // the client side. Here we detect the transition between no client side |
529 // dialog and at least one dialog so activatable state is properly | 569 // dialog and at least one dialog so activatable state is properly |
530 // updated. | 570 // updated. |
531 if (container_ != ash::kShellWindowId_SystemModalContainer) { | 571 if (container_ != ash::kShellWindowId_SystemModalContainer) { |
532 LOG(ERROR) | 572 LOG(ERROR) |
533 << "Only a window in SystemModalContainer can change the modality"; | 573 << "Only a window in SystemModalContainer can change the modality"; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 // static | 741 // static |
702 void ShellSurface::SetMainSurface(aura::Window* window, Surface* surface) { | 742 void ShellSurface::SetMainSurface(aura::Window* window, Surface* surface) { |
703 window->SetProperty(kMainSurfaceKey, surface); | 743 window->SetProperty(kMainSurfaceKey, surface); |
704 } | 744 } |
705 | 745 |
706 // static | 746 // static |
707 Surface* ShellSurface::GetMainSurface(const aura::Window* window) { | 747 Surface* ShellSurface::GetMainSurface(const aura::Window* window) { |
708 return window->GetProperty(kMainSurfaceKey); | 748 return window->GetProperty(kMainSurfaceKey); |
709 } | 749 } |
710 | 750 |
| 751 // static |
| 752 bool ShellSurface::IsUnsafeIconPngDataKey(const void* key) { |
| 753 return key == kUnsafeIconPngDataKey; |
| 754 } |
| 755 |
| 756 // static |
| 757 const std::string* ShellSurface::GetUnsafeIconPngData( |
| 758 const aura::Window* window) { |
| 759 return window->GetProperty(kUnsafeIconPngDataKey); |
| 760 } |
| 761 |
| 762 // static |
| 763 void ShellSurface::SetUnsafeIconPngData(aura::Window* window, |
| 764 std::string* unsage_icon_png_data) { |
| 765 return window->SetProperty(kUnsafeIconPngDataKey, unsage_icon_png_data); |
| 766 } |
| 767 |
711 std::unique_ptr<base::trace_event::TracedValue> ShellSurface::AsTracedValue() | 768 std::unique_ptr<base::trace_event::TracedValue> ShellSurface::AsTracedValue() |
712 const { | 769 const { |
713 std::unique_ptr<base::trace_event::TracedValue> value( | 770 std::unique_ptr<base::trace_event::TracedValue> value( |
714 new base::trace_event::TracedValue()); | 771 new base::trace_event::TracedValue()); |
715 value->SetString("title", base::UTF16ToUTF8(title_)); | 772 value->SetString("title", base::UTF16ToUTF8(title_)); |
716 std::string application_id; | 773 std::string application_id; |
717 if (GetWidget() && GetWidget()->GetNativeWindow()) | 774 if (GetWidget() && GetWidget()->GetNativeWindow()) |
718 application_id = GetApplicationId(GetWidget()->GetNativeWindow()); | 775 application_id = GetApplicationId(GetWidget()->GetNativeWindow()); |
719 value->SetString("application_id", application_id); | 776 value->SetString("application_id", application_id); |
720 return value; | 777 return value; |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1193 widget_ = new ShellSurfaceWidget(this); | 1250 widget_ = new ShellSurfaceWidget(this); |
1194 widget_->Init(params); | 1251 widget_->Init(params); |
1195 | 1252 |
1196 aura::Window* window = widget_->GetNativeWindow(); | 1253 aura::Window* window = widget_->GetNativeWindow(); |
1197 window->SetName("ExoShellSurface"); | 1254 window->SetName("ExoShellSurface"); |
1198 window->SetProperty(aura::client::kAccessibilityFocusFallsbackToWidgetKey, | 1255 window->SetProperty(aura::client::kAccessibilityFocusFallsbackToWidgetKey, |
1199 false); | 1256 false); |
1200 window->AddChild(surface_->window()); | 1257 window->AddChild(surface_->window()); |
1201 window->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter(widget_))); | 1258 window->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter(widget_))); |
1202 SetApplicationId(window, application_id_); | 1259 SetApplicationId(window, application_id_); |
| 1260 if (!unsafe_icon_png_.empty()) |
| 1261 SetUnsafeIconPngData(window, &unsafe_icon_png_); |
1203 SetMainSurface(window, surface_); | 1262 SetMainSurface(window, surface_); |
1204 | 1263 |
1205 // Start tracking changes to window bounds and window state. | 1264 // Start tracking changes to window bounds and window state. |
1206 window->AddObserver(this); | 1265 window->AddObserver(this); |
1207 ash::wm::WindowState* window_state = ash::wm::GetWindowState(window); | 1266 ash::wm::WindowState* window_state = ash::wm::GetWindowState(window); |
1208 window_state->AddObserver(this); | 1267 window_state->AddObserver(this); |
1209 | 1268 |
1210 // Allow the client to request bounds that do not fill the entire work area | 1269 // Allow the client to request bounds that do not fill the entire work area |
1211 // when maximized, or the entire display when fullscreen. | 1270 // when maximized, or the entire display when fullscreen. |
1212 window_state->set_allow_set_bounds_direct(bounds_mode_ == BoundsMode::CLIENT); | 1271 window_state->set_allow_set_bounds_direct(bounds_mode_ == BoundsMode::CLIENT); |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1737 gfx::Point ShellSurface::GetMouseLocation() const { | 1796 gfx::Point ShellSurface::GetMouseLocation() const { |
1738 aura::Window* const root_window = widget_->GetNativeWindow()->GetRootWindow(); | 1797 aura::Window* const root_window = widget_->GetNativeWindow()->GetRootWindow(); |
1739 gfx::Point location = | 1798 gfx::Point location = |
1740 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot(); | 1799 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot(); |
1741 aura::Window::ConvertPointToTarget( | 1800 aura::Window::ConvertPointToTarget( |
1742 root_window, widget_->GetNativeWindow()->parent(), &location); | 1801 root_window, widget_->GetNativeWindow()->parent(), &location); |
1743 return location; | 1802 return location; |
1744 } | 1803 } |
1745 | 1804 |
1746 } // namespace exo | 1805 } // namespace exo |
OLD | NEW |