| 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/aura/wm_window_aura.h" | 9 #include "ash/aura/wm_window_aura.h" |
| 10 #include "ash/common/shelf/wm_shelf.h" | 10 #include "ash/common/shelf/wm_shelf.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "ui/wm/core/coordinate_conversion.h" | 36 #include "ui/wm/core/coordinate_conversion.h" |
| 37 #include "ui/wm/core/shadow.h" | 37 #include "ui/wm/core/shadow.h" |
| 38 #include "ui/wm/core/shadow_controller.h" | 38 #include "ui/wm/core/shadow_controller.h" |
| 39 #include "ui/wm/core/shadow_types.h" | 39 #include "ui/wm/core/shadow_types.h" |
| 40 #include "ui/wm/core/window_util.h" | 40 #include "ui/wm/core/window_util.h" |
| 41 | 41 |
| 42 #if defined(OS_CHROMEOS) | 42 #if defined(OS_CHROMEOS) |
| 43 #include "chromeos/audio/chromeos_sounds.h" | 43 #include "chromeos/audio/chromeos_sounds.h" |
| 44 #endif | 44 #endif |
| 45 | 45 |
| 46 DECLARE_WINDOW_PROPERTY_TYPE(std::string*) |
| 47 |
| 46 namespace exo { | 48 namespace exo { |
| 47 namespace { | 49 namespace { |
| 48 | 50 |
| 49 // This is a struct for accelerator keys used to close ShellSurfaces. | 51 // This is a struct for accelerator keys used to close ShellSurfaces. |
| 50 const struct Accelerator { | 52 const struct Accelerator { |
| 51 ui::KeyboardCode keycode; | 53 ui::KeyboardCode keycode; |
| 52 int modifiers; | 54 int modifiers; |
| 53 } kCloseWindowAccelerators[] = { | 55 } kCloseWindowAccelerators[] = { |
| 54 {ui::VKEY_W, ui::EF_CONTROL_DOWN}, | 56 {ui::VKEY_W, ui::EF_CONTROL_DOWN}, |
| 55 {ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN}, | 57 {ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN}, |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 aura::Window* window = shell_surface_->widget_->GetNativeWindow(); | 322 aura::Window* window = shell_surface_->widget_->GetNativeWindow(); |
| 321 DCHECK_EQ(window->GetProperty(aura::client::kAnimationsDisabledKey), true); | 323 DCHECK_EQ(window->GetProperty(aura::client::kAnimationsDisabledKey), true); |
| 322 window->SetProperty(aura::client::kAnimationsDisabledKey, | 324 window->SetProperty(aura::client::kAnimationsDisabledKey, |
| 323 saved_animations_disabled_); | 325 saved_animations_disabled_); |
| 324 } | 326 } |
| 325 } | 327 } |
| 326 | 328 |
| 327 //////////////////////////////////////////////////////////////////////////////// | 329 //////////////////////////////////////////////////////////////////////////////// |
| 328 // ShellSurface, public: | 330 // ShellSurface, public: |
| 329 | 331 |
| 332 DEFINE_LOCAL_WINDOW_PROPERTY_KEY(std::string*, kApplicationIdKey, nullptr) |
| 330 DEFINE_LOCAL_WINDOW_PROPERTY_KEY(Surface*, kMainSurfaceKey, nullptr) | 333 DEFINE_LOCAL_WINDOW_PROPERTY_KEY(Surface*, kMainSurfaceKey, nullptr) |
| 331 | 334 |
| 332 ShellSurface::ShellSurface(Surface* surface, | 335 ShellSurface::ShellSurface(Surface* surface, |
| 333 ShellSurface* parent, | 336 ShellSurface* parent, |
| 334 const gfx::Rect& initial_bounds, | 337 const gfx::Rect& initial_bounds, |
| 335 bool activatable, | 338 bool activatable, |
| 336 int container) | 339 int container) |
| 337 : widget_(nullptr), | 340 : widget_(nullptr), |
| 338 surface_(surface), | 341 surface_(surface), |
| 339 parent_(parent ? parent->GetWidget()->GetNativeWindow() : nullptr), | 342 parent_(parent ? parent->GetWidget()->GetNativeWindow() : nullptr), |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 << "Only a window in SystemModalContainer can change the modality"; | 525 << "Only a window in SystemModalContainer can change the modality"; |
| 523 return; | 526 return; |
| 524 } | 527 } |
| 525 widget_->GetNativeWindow()->SetProperty( | 528 widget_->GetNativeWindow()->SetProperty( |
| 526 aura::client::kModalKey, | 529 aura::client::kModalKey, |
| 527 system_modal ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE); | 530 system_modal ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE); |
| 528 } | 531 } |
| 529 | 532 |
| 530 // static | 533 // static |
| 531 void ShellSurface::SetApplicationId(aura::Window* window, | 534 void ShellSurface::SetApplicationId(aura::Window* window, |
| 532 const std::string& id) { | 535 std::string* application_id) { |
| 533 TRACE_EVENT1("exo", "ShellSurface::SetApplicationId", "application_id", id); | 536 window->SetProperty(kApplicationIdKey, application_id); |
| 534 window->SetProperty(aura::client::kAppIdKey, new std::string(id)); | |
| 535 } | 537 } |
| 536 | 538 |
| 537 // static | 539 // static |
| 538 const std::string ShellSurface::GetApplicationId(aura::Window* window) { | 540 const std::string ShellSurface::GetApplicationId(aura::Window* window) { |
| 539 std::string* string_ptr = window->GetProperty(aura::client::kAppIdKey); | 541 std::string* string_ptr = window->GetProperty(kApplicationIdKey); |
| 540 return string_ptr ? *string_ptr : std::string(); | 542 return string_ptr ? *string_ptr : std::string(); |
| 541 } | 543 } |
| 542 | 544 |
| 543 void ShellSurface::SetApplicationId(const std::string& application_id) { | 545 void ShellSurface::SetApplicationId(const std::string& application_id) { |
| 544 SetApplicationId(widget_->GetNativeWindow(), application_id); | 546 TRACE_EVENT1("exo", "ShellSurface::SetApplicationId", "application_id", |
| 547 application_id); |
| 548 |
| 549 application_id_ = application_id; |
| 545 } | 550 } |
| 546 | 551 |
| 547 void ShellSurface::Move() { | 552 void ShellSurface::Move() { |
| 548 TRACE_EVENT0("exo", "ShellSurface::Move"); | 553 TRACE_EVENT0("exo", "ShellSurface::Move"); |
| 549 | 554 |
| 550 if (widget_ && !widget_->movement_disabled()) | 555 if (widget_ && !widget_->movement_disabled()) |
| 551 AttemptToStartDrag(HTCAPTION); | 556 AttemptToStartDrag(HTCAPTION); |
| 552 } | 557 } |
| 553 | 558 |
| 554 void ShellSurface::Resize(int component) { | 559 void ShellSurface::Resize(int component) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 // static | 619 // static |
| 615 Surface* ShellSurface::GetMainSurface(const aura::Window* window) { | 620 Surface* ShellSurface::GetMainSurface(const aura::Window* window) { |
| 616 return window->GetProperty(kMainSurfaceKey); | 621 return window->GetProperty(kMainSurfaceKey); |
| 617 } | 622 } |
| 618 | 623 |
| 619 std::unique_ptr<base::trace_event::TracedValue> ShellSurface::AsTracedValue() | 624 std::unique_ptr<base::trace_event::TracedValue> ShellSurface::AsTracedValue() |
| 620 const { | 625 const { |
| 621 std::unique_ptr<base::trace_event::TracedValue> value( | 626 std::unique_ptr<base::trace_event::TracedValue> value( |
| 622 new base::trace_event::TracedValue()); | 627 new base::trace_event::TracedValue()); |
| 623 value->SetString("title", base::UTF16ToUTF8(title_)); | 628 value->SetString("title", base::UTF16ToUTF8(title_)); |
| 624 std::string application_id; | 629 value->SetString("application_id", application_id_); |
| 625 if (GetWidget() && GetWidget()->GetNativeWindow()) | |
| 626 application_id = GetApplicationId(GetWidget()->GetNativeWindow()); | |
| 627 value->SetString("application_id", application_id); | |
| 628 return value; | 630 return value; |
| 629 } | 631 } |
| 630 | 632 |
| 631 //////////////////////////////////////////////////////////////////////////////// | 633 //////////////////////////////////////////////////////////////////////////////// |
| 632 // SurfaceDelegate overrides: | 634 // SurfaceDelegate overrides: |
| 633 | 635 |
| 634 void ShellSurface::OnSurfaceCommit() { | 636 void ShellSurface::OnSurfaceCommit() { |
| 635 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); | 637 surface_->CheckIfSurfaceHierarchyNeedsCommitToNewSurfaces(); |
| 636 surface_->CommitSurfaceHierarchy(); | 638 surface_->CommitSurfaceHierarchy(); |
| 637 | 639 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 : views::Widget::InitParams::ACTIVATABLE_NO; | 1016 : views::Widget::InitParams::ACTIVATABLE_NO; |
| 1015 | 1017 |
| 1016 // Note: NativeWidget owns this widget. | 1018 // Note: NativeWidget owns this widget. |
| 1017 widget_ = new ShellSurfaceWidget(this); | 1019 widget_ = new ShellSurfaceWidget(this); |
| 1018 widget_->Init(params); | 1020 widget_->Init(params); |
| 1019 | 1021 |
| 1020 aura::Window* window = widget_->GetNativeWindow(); | 1022 aura::Window* window = widget_->GetNativeWindow(); |
| 1021 window->SetName("ExoShellSurface"); | 1023 window->SetName("ExoShellSurface"); |
| 1022 window->AddChild(surface_->window()); | 1024 window->AddChild(surface_->window()); |
| 1023 window->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter(widget_))); | 1025 window->SetEventTargeter(base::WrapUnique(new CustomWindowTargeter(widget_))); |
| 1026 SetApplicationId(window, &application_id_); |
| 1024 SetMainSurface(window, surface_); | 1027 SetMainSurface(window, surface_); |
| 1025 | 1028 |
| 1026 // Start tracking changes to window bounds and window state. | 1029 // Start tracking changes to window bounds and window state. |
| 1027 window->AddObserver(this); | 1030 window->AddObserver(this); |
| 1028 ash::wm::WindowState* window_state = ash::wm::GetWindowState(window); | 1031 ash::wm::WindowState* window_state = ash::wm::GetWindowState(window); |
| 1029 window_state->AddObserver(this); | 1032 window_state->AddObserver(this); |
| 1030 | 1033 |
| 1031 // Absolete positioned shell surfaces may request the bounds that does not | 1034 // Absolete positioned shell surfaces may request the bounds that does not |
| 1032 // fill the entire work area / display in maximized / fullscreen state. | 1035 // fill the entire work area / display in maximized / fullscreen state. |
| 1033 // Allow such clients to update the bounds in these states. | 1036 // Allow such clients to update the bounds in these states. |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1395 shadow_overlay_->layer()->Add(shadow->layer()); | 1398 shadow_overlay_->layer()->Add(shadow->layer()); |
| 1396 window->AddChild(shadow_overlay_); | 1399 window->AddChild(shadow_overlay_); |
| 1397 shadow_overlay_->Show(); | 1400 shadow_overlay_->Show(); |
| 1398 } | 1401 } |
| 1399 shadow_overlay_->SetBounds(shadow_bounds); | 1402 shadow_overlay_->SetBounds(shadow_bounds); |
| 1400 shadow->SetContentBounds(gfx::Rect(shadow_bounds.size())); | 1403 shadow->SetContentBounds(gfx::Rect(shadow_bounds.size())); |
| 1401 } | 1404 } |
| 1402 } | 1405 } |
| 1403 | 1406 |
| 1404 } // namespace exo | 1407 } // namespace exo |
| OLD | NEW |