Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(531)

Side by Side Diff: components/exo/shell_surface.cc

Issue 1412093006: components: Add Exosphere component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove some ifdefs Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/exo/shell_surface.h ('k') | components/exo/shell_surface_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/base/hit_test.h"
16 #include "ui/views/widget/widget.h"
17
18 namespace exo {
19 namespace {
20
21 class CustomFrameView : public views::NonClientFrameView {
22 public:
23 explicit CustomFrameView(views::Widget* widget) : widget_(widget) {}
24 ~CustomFrameView() override {}
25
26 // Overridden from views::NonClientFrameView:
27 gfx::Rect GetBoundsForClientView() const override { return bounds(); }
28 gfx::Rect GetWindowBoundsForClientBounds(
29 const gfx::Rect& client_bounds) const override {
30 return client_bounds;
31 }
32 int NonClientHitTest(const gfx::Point& point) override {
33 return widget_->client_view()->NonClientHitTest(point);
34 }
35 void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask) override {}
36 void ResetWindowControls() override {}
37 void UpdateWindowIcon() override {}
38 void UpdateWindowTitle() override {}
39 void SizeConstraintsChanged() override {}
40
41 private:
42 views::Widget* const widget_;
43
44 DISALLOW_COPY_AND_ASSIGN(CustomFrameView);
45 };
46
47 } // namespace
48
49 ////////////////////////////////////////////////////////////////////////////////
50 // ShellSurface, public:
51
52 ShellSurface::ShellSurface(Surface* surface)
53 : surface_(surface), show_state_(ui::SHOW_STATE_END) {
54 surface_->SetSurfaceDelegate(this);
55 }
56
57 ShellSurface::~ShellSurface() {
58 if (surface_)
59 surface_->SetSurfaceDelegate(nullptr);
60 if (widget_)
61 widget_->CloseNow();
62 }
63
64 void ShellSurface::Show() {
65 TRACE_EVENT0("exo", "ShellSurface::Show");
66
67 if (!widget_ && show_state_ == ui::SHOW_STATE_END)
68 show_state_ = ui::SHOW_STATE_DEFAULT;
69 }
70
71 void ShellSurface::SetToplevel() {
72 TRACE_EVENT0("exo", "ShellSurface::SetToplevel");
73
74 if (!widget_)
75 show_state_ = ui::SHOW_STATE_NORMAL;
76 }
77
78 void ShellSurface::SetFullscreen(bool fullscreen) {
79 TRACE_EVENT1("exo", "ShellSurface::SetFullscreen", "fullscreen", fullscreen);
80
81 if (widget_) {
82 widget_->SetFullscreen(fullscreen);
83 return;
84 }
85
86 show_state_ = fullscreen ? ui::SHOW_STATE_FULLSCREEN : ui::SHOW_STATE_DEFAULT;
87 }
88
89 void ShellSurface::SetTitle(const base::string16& title) {
90 TRACE_EVENT1("exo", "ShellSurface::SetTitle", "title",
91 base::UTF16ToUTF8(title));
92
93 title_ = title;
94 if (widget_)
95 widget_->UpdateWindowTitle();
96 }
97
98 scoped_refptr<base::trace_event::TracedValue> ShellSurface::AsTracedValue()
99 const {
100 scoped_refptr<base::trace_event::TracedValue> value =
101 new base::trace_event::TracedValue;
102 value->SetString("title", base::UTF16ToUTF8(title_));
103 return value;
104 }
105
106 ////////////////////////////////////////////////////////////////////////////////
107 // SurfaceDelegate overrides:
108
109 void ShellSurface::OnSurfaceDestroying() {
110 surface_ = nullptr;
111 }
112
113 void ShellSurface::OnSurfaceCommit() {
114 if (widget_ || show_state_ == ui::SHOW_STATE_END)
115 return;
116
117 views::Widget::InitParams params;
118 params.type = views::Widget::InitParams::TYPE_WINDOW;
119 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
120 params.delegate = this;
121 params.shadow_type = show_state_ == ui::SHOW_STATE_NORMAL
122 ? views::Widget::InitParams::SHADOW_TYPE_DROP
123 : views::Widget::InitParams::SHADOW_TYPE_NONE;
124 params.opacity = show_state_ == ui::SHOW_STATE_NORMAL
125 ? views::Widget::InitParams::OPAQUE_WINDOW
126 : views::Widget::InitParams::TRANSLUCENT_WINDOW;
127 params.show_state = show_state_;
128 params.parent = ash::Shell::GetContainer(
129 ash::Shell::GetPrimaryRootWindow(), ash::kShellWindowId_DefaultContainer);
130 widget_.reset(new views::Widget);
131 widget_->Init(params);
132 widget_->GetNativeWindow()->set_owned_by_parent(false);
133 widget_->GetNativeView()->SetName("ShellSurface");
134 widget_->Show();
135 }
136
137 ////////////////////////////////////////////////////////////////////////////////
138 // views::WidgetDelegate overrides:
139
140 base::string16 ShellSurface::GetWindowTitle() const {
141 return title_;
142 }
143
144 views::Widget* ShellSurface::GetWidget() {
145 return widget_.get();
146 }
147
148 const views::Widget* ShellSurface::GetWidget() const {
149 return widget_.get();
150 }
151
152 views::View* ShellSurface::GetContentsView() {
153 return surface_;
154 }
155
156 views::NonClientFrameView* ShellSurface::CreateNonClientFrameView(
157 views::Widget* widget) {
158 // Default show state is borderless and requires a custom frame view as the
159 // default one does not support this.
160 return show_state_ != ui::SHOW_STATE_NORMAL ? new CustomFrameView(widget)
161 : nullptr;
162 }
163
164 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/shell_surface.h ('k') | components/exo/shell_surface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698