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

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: fix build issues and remove wayland_bindings.h 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 (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 show_state_ = ui::SHOW_STATE_NORMAL;
75 }
76
77 void ShellSurface::SetFullscreen(bool fullscreen) {
78 TRACE_EVENT1("exo", "ShellSurface::SetFullscreen", "fullscreen", fullscreen);
79
80 if (widget_)
81 widget_->SetFullscreen(fullscreen);
82
83 show_state_ = fullscreen ? ui::SHOW_STATE_FULLSCREEN : ui::SHOW_STATE_DEFAULT;
84 }
85
86 void ShellSurface::SetTitle(const base::string16& title) {
87 TRACE_EVENT1("exo", "ShellSurface::SetTitle", "title",
88 base::UTF16ToUTF8(title));
89
90 title_ = title;
91 if (widget_)
92 widget_->UpdateWindowTitle();
93 }
94
95 scoped_refptr<base::trace_event::TracedValue> ShellSurface::AsTracedValue()
96 const {
97 scoped_refptr<base::trace_event::TracedValue> value =
98 new base::trace_event::TracedValue;
99 value->SetString("title", base::UTF16ToUTF8(title_));
100 return value;
101 }
102
103 ////////////////////////////////////////////////////////////////////////////////
104 // SurfaceDelegate overrides:
105
106 void ShellSurface::OnSurfaceDestroying() {
107 surface_ = nullptr;
108 }
109
110 void ShellSurface::OnSurfaceCommit() {
111 if (widget_ || show_state_ == ui::SHOW_STATE_END)
112 return;
113
114 views::Widget::InitParams params;
115 params.type = views::Widget::InitParams::TYPE_WINDOW;
116 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
117 params.delegate = this;
118 params.shadow_type = show_state_ == ui::SHOW_STATE_NORMAL
119 ? views::Widget::InitParams::SHADOW_TYPE_DROP
120 : views::Widget::InitParams::SHADOW_TYPE_NONE;
121 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
122 params.show_state = show_state_;
123 params.parent = ash::Shell::GetContainer(
124 ash::Shell::GetPrimaryRootWindow(), ash::kShellWindowId_DefaultContainer);
125 widget_.reset(new views::Widget);
126 widget_->Init(params);
127 widget_->GetNativeWindow()->set_owned_by_parent(false);
128 widget_->GetNativeView()->SetName("ShellSurface");
129 widget_->Show();
130 }
131
132 ////////////////////////////////////////////////////////////////////////////////
133 // views::WidgetDelegate overrides:
134
135 base::string16 ShellSurface::GetWindowTitle() const {
136 return title_;
137 }
138
139 views::Widget* ShellSurface::GetWidget() {
140 return widget_.get();
141 }
142
143 const views::Widget* ShellSurface::GetWidget() const {
144 return widget_.get();
145 }
146
147 views::View* ShellSurface::GetContentsView() {
148 return surface_;
149 }
150
151 views::NonClientFrameView* ShellSurface::CreateNonClientFrameView(
reveman 2015/11/18 06:48:36 Note: added this as using TYPE_WINDOW_FRAMELESS ma
152 views::Widget* widget) {
153 // Normal show state is borderless and requires a custom frame view as the
154 // default one does not support this.
155 return show_state_ != ui::SHOW_STATE_NORMAL ? new CustomFrameView(widget)
156 : nullptr;
157 }
158
159 } // 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