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