OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/exo/shell_surface.h" |
| 6 |
| 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" |
| 9 #include "base/logging.h" |
| 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/trace_event/trace_event.h" |
| 12 #include "base/trace_event/trace_event_argument.h" |
| 13 #include "components/exo/surface.h" |
| 14 #include "ui/aura/window.h" |
| 15 #include "ui/views/widget/widget.h" |
| 16 |
| 17 namespace exo { |
| 18 |
| 19 //////////////////////////////////////////////////////////////////////////////// |
| 20 // ShellSurface, public: |
| 21 |
| 22 ShellSurface::ShellSurface(Surface* surface) |
| 23 : surface_(surface), show_state_(ui::SHOW_STATE_END) { |
| 24 surface_->SetSurfaceDelegate(this); |
| 25 } |
| 26 |
| 27 ShellSurface::~ShellSurface() { |
| 28 if (surface_) |
| 29 surface_->SetSurfaceDelegate(nullptr); |
| 30 if (widget_) |
| 31 widget_->CloseNow(); |
| 32 } |
| 33 |
| 34 void ShellSurface::Show() { |
| 35 TRACE_EVENT0("exo", "ShellSurface::Show"); |
| 36 |
| 37 if (show_state_ == ui::SHOW_STATE_END) |
| 38 show_state_ = ui::SHOW_STATE_DEFAULT; |
| 39 } |
| 40 |
| 41 void ShellSurface::SetToplevel() { |
| 42 TRACE_EVENT0("exo", "ShellSurface::SetToplevel"); |
| 43 |
| 44 show_state_ = ui::SHOW_STATE_NORMAL; |
| 45 } |
| 46 |
| 47 void ShellSurface::SetFullscreen(bool fullscreen) { |
| 48 TRACE_EVENT1("exo", "ShellSurface::SetFullscreen", "fullscreen", fullscreen); |
| 49 |
| 50 if (widget_) |
| 51 widget_->SetFullscreen(fullscreen); |
| 52 |
| 53 show_state_ = fullscreen ? ui::SHOW_STATE_FULLSCREEN : ui::SHOW_STATE_DEFAULT; |
| 54 } |
| 55 |
| 56 void ShellSurface::SetTitle(const base::string16& title) { |
| 57 TRACE_EVENT1("exo", "ShellSurface::SetTitle", "title", |
| 58 base::UTF16ToUTF8(title)); |
| 59 |
| 60 title_ = title; |
| 61 if (widget_) |
| 62 widget_->UpdateWindowTitle(); |
| 63 } |
| 64 |
| 65 scoped_refptr<base::trace_event::TracedValue> ShellSurface::AsTracedValue() |
| 66 const { |
| 67 scoped_refptr<base::trace_event::TracedValue> value = |
| 68 new base::trace_event::TracedValue; |
| 69 value->SetString("title", base::UTF16ToUTF8(title_)); |
| 70 return value; |
| 71 } |
| 72 |
| 73 //////////////////////////////////////////////////////////////////////////////// |
| 74 // SurfaceDelegate overrides: |
| 75 |
| 76 void ShellSurface::OnSurfaceDestroying() { |
| 77 surface_ = nullptr; |
| 78 } |
| 79 |
| 80 void ShellSurface::OnSurfaceCommit() { |
| 81 if (widget_ || show_state_ == ui::SHOW_STATE_END) |
| 82 return; |
| 83 |
| 84 views::Widget::InitParams params; |
| 85 params.type = show_state_ == ui::SHOW_STATE_NORMAL |
| 86 ? views::Widget::InitParams::TYPE_WINDOW |
| 87 : views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; |
| 88 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 89 params.delegate = this; |
| 90 params.shadow_type = views::Widget::InitParams::SHADOW_TYPE_DEFAULT; |
| 91 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 92 params.show_state = show_state_; |
| 93 params.parent = ash::Shell::GetContainer( |
| 94 ash::Shell::GetPrimaryRootWindow(), ash::kShellWindowId_DefaultContainer); |
| 95 widget_.reset(new views::Widget); |
| 96 widget_->Init(params); |
| 97 widget_->GetNativeWindow()->set_owned_by_parent(false); |
| 98 widget_->GetNativeView()->SetName("ShellSurface"); |
| 99 widget_->Show(); |
| 100 } |
| 101 |
| 102 //////////////////////////////////////////////////////////////////////////////// |
| 103 // views::WidgetDelegate overrides: |
| 104 |
| 105 base::string16 ShellSurface::GetWindowTitle() const { |
| 106 return title_; |
| 107 } |
| 108 |
| 109 views::Widget* ShellSurface::GetWidget() { |
| 110 return widget_.get(); |
| 111 } |
| 112 |
| 113 const views::Widget* ShellSurface::GetWidget() const { |
| 114 return widget_.get(); |
| 115 } |
| 116 |
| 117 views::View* ShellSurface::GetContentsView() { |
| 118 return surface_; |
| 119 } |
| 120 |
| 121 } // namespace exo |
OLD | NEW |