window.cc 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777
  1. // Copyright (c) 2012 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. #include "ui/aura/window.h"
  5. #include <stddef.h>
  6. #include <algorithm>
  7. #include <utility>
  8. #include "base/bind.h"
  9. #include "base/callback.h"
  10. #include "base/callback_helpers.h"
  11. #include "base/containers/adapters.h"
  12. #include "base/containers/contains.h"
  13. #include "base/logging.h"
  14. #include "base/memory/raw_ptr.h"
  15. #include "base/observer_list.h"
  16. #include "base/strings/string_number_conversions.h"
  17. #include "base/strings/string_util.h"
  18. #include "base/strings/stringprintf.h"
  19. #include "cc/mojo_embedder/async_layer_tree_frame_sink.h"
  20. #include "cc/trees/layer_tree_frame_sink.h"
  21. #include "components/viz/common/features.h"
  22. #include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
  23. #include "components/viz/host/host_frame_sink_manager.h"
  24. #include "mojo/public/cpp/bindings/pending_receiver.h"
  25. #include "mojo/public/cpp/bindings/pending_remote.h"
  26. #include "third_party/skia/include/core/SkPath.h"
  27. #include "ui/aura/client/aura_constants.h"
  28. #include "ui/aura/client/capture_client.h"
  29. #include "ui/aura/client/cursor_client.h"
  30. #include "ui/aura/client/event_client.h"
  31. #include "ui/aura/client/focus_client.h"
  32. #include "ui/aura/client/screen_position_client.h"
  33. #include "ui/aura/client/visibility_client.h"
  34. #include "ui/aura/client/window_stacking_client.h"
  35. #include "ui/aura/env.h"
  36. #include "ui/aura/layout_manager.h"
  37. #include "ui/aura/scoped_keyboard_hook.h"
  38. #include "ui/aura/window_delegate.h"
  39. #include "ui/aura/window_event_dispatcher.h"
  40. #include "ui/aura/window_observer.h"
  41. #include "ui/aura/window_occlusion_tracker.h"
  42. #include "ui/aura/window_targeter.h"
  43. #include "ui/aura/window_tracker.h"
  44. #include "ui/aura/window_tree_host.h"
  45. #include "ui/base/layout.h"
  46. #include "ui/base/metadata/base_type_conversion.h"
  47. #include "ui/base/metadata/metadata_impl_macros.h"
  48. #include "ui/base/ui_base_features.h"
  49. #include "ui/compositor/compositor.h"
  50. #include "ui/compositor/layer.h"
  51. #include "ui/compositor/layer_animator.h"
  52. #include "ui/display/display.h"
  53. #include "ui/display/screen.h"
  54. #include "ui/events/event_target_iterator.h"
  55. #include "ui/events/keycodes/dom/dom_code.h"
  56. #include "ui/gfx/canvas.h"
  57. #include "ui/gfx/scoped_canvas.h"
  58. DEFINE_ENUM_CONVERTERS(
  59. aura::client::WindowType,
  60. {aura::client::WINDOW_TYPE_UNKNOWN, u"WINDOW_TYPE_UNKNOWN"},
  61. {aura::client::WINDOW_TYPE_NORMAL, u"WINDOW_TYPE_NORMAL"},
  62. {aura::client::WINDOW_TYPE_POPUP, u"WINDOW_TYPE_POPUP"},
  63. {aura::client::WINDOW_TYPE_CONTROL, u"WINDOW_TYPE_CONTROL"},
  64. {aura::client::WINDOW_TYPE_MENU, u"WINDOW_TYPE_MENU"},
  65. {aura::client::WINDOW_TYPE_TOOLTIP, u"WINDOW_TYPE_TOOLTIP"})
  66. DEFINE_ENUM_CONVERTERS(aura::Window::OcclusionState,
  67. {aura::Window::OcclusionState::UNKNOWN, u"UNKNOWN"},
  68. {aura::Window::OcclusionState::VISIBLE, u"VISIBLE"},
  69. {aura::Window::OcclusionState::OCCLUDED, u"OCCLUDED"},
  70. {aura::Window::OcclusionState::HIDDEN, u"HIDDEN"})
  71. namespace ui {
  72. namespace metadata {
  73. template <>
  74. struct TypeConverter<viz::SurfaceId> : public BaseTypeConverter<true> {
  75. static std::u16string ToString(const viz::SurfaceId& source_value);
  76. static absl::optional<viz::SurfaceId> FromString(
  77. const std::u16string& source_value);
  78. static ValidStrings GetValidStrings();
  79. };
  80. // static
  81. std::u16string TypeConverter<viz::SurfaceId>::ToString(
  82. const viz::SurfaceId& source_value) {
  83. return source_value.is_valid() ? base::UTF8ToUTF16(source_value.ToString())
  84. : u"<none>";
  85. }
  86. // static
  87. absl::optional<viz::SurfaceId> TypeConverter<viz::SurfaceId>::FromString(
  88. const std::u16string& source_value) {
  89. return absl::nullopt;
  90. }
  91. // static
  92. ValidStrings TypeConverter<viz::SurfaceId>::GetValidStrings() {
  93. return ValidStrings();
  94. }
  95. } // namespace metadata
  96. } // namespace ui
  97. namespace {
  98. // This enum is used to construct a unique property changed callback key from
  99. // the address of the `bounds_` field by using these values as an offset.
  100. enum BoundsCallbackIndex : int {
  101. kBoundsX,
  102. kBoundsY,
  103. kBoundsWidth,
  104. kBoundsHeight,
  105. };
  106. } // namespace
  107. namespace aura {
  108. namespace {
  109. static const char* kExo = "Exo";
  110. class ScopedCursorHider {
  111. public:
  112. explicit ScopedCursorHider(Window* window)
  113. : window_(window), hid_cursor_(false) {
  114. if (!window_->IsRootWindow())
  115. return;
  116. const bool cursor_is_in_bounds = window_->GetBoundsInScreen().Contains(
  117. Env::GetInstance()->last_mouse_location());
  118. client::CursorClient* cursor_client = client::GetCursorClient(window_);
  119. if (cursor_is_in_bounds && cursor_client &&
  120. cursor_client->IsCursorVisible()) {
  121. cursor_client->HideCursor();
  122. hid_cursor_ = true;
  123. }
  124. }
  125. ScopedCursorHider(const ScopedCursorHider&) = delete;
  126. ScopedCursorHider& operator=(const ScopedCursorHider&) = delete;
  127. ~ScopedCursorHider() {
  128. if (!window_->IsRootWindow())
  129. return;
  130. // Update the device scale factor of the cursor client only when the last
  131. // mouse location is on this root window.
  132. if (hid_cursor_) {
  133. client::CursorClient* cursor_client = client::GetCursorClient(window_);
  134. if (cursor_client) {
  135. const display::Display& display =
  136. display::Screen::GetScreen()->GetDisplayNearestWindow(window_);
  137. cursor_client->SetDisplay(display);
  138. cursor_client->ShowCursor();
  139. }
  140. }
  141. }
  142. private:
  143. raw_ptr<Window> window_;
  144. bool hid_cursor_;
  145. };
  146. } // namespace
  147. Window::Window(WindowDelegate* delegate, client::WindowType type)
  148. : type_(type),
  149. delegate_(delegate),
  150. event_targeting_policy_(
  151. aura::EventTargetingPolicy::kTargetAndDescendants),
  152. restore_event_targeting_policy_(
  153. aura::EventTargetingPolicy::kTargetAndDescendants),
  154. // Don't notify newly added observers during notification. This causes
  155. // problems for code that adds an observer as part of an observer
  156. // notification (such as the workspace code).
  157. observers_(base::ObserverListPolicy::EXISTING_ONLY) {
  158. SetTargetHandler(delegate_);
  159. }
  160. Window::~Window() {
  161. is_destroying_ = true;
  162. WindowOcclusionTracker::ScopedPause pause_occlusion_tracking;
  163. if (layer()->owner() == this)
  164. layer()->CompleteAllAnimations();
  165. // Let the delegate know we're in the processing of destroying.
  166. if (delegate_)
  167. delegate_->OnWindowDestroying(this);
  168. for (WindowObserver& observer : observers_)
  169. observer.OnWindowDestroying(this);
  170. // While we are being destroyed, our target handler may also be in the
  171. // process of destruction or already destroyed, so do not forward any
  172. // input events at the ui::EP_TARGET phase.
  173. SetTargetHandler(nullptr);
  174. // TODO(beng): See comment in window_event_dispatcher.h. This shouldn't be
  175. // necessary but unfortunately is right now due to ordering
  176. // peculiarities. WED must be notified _after_ other observers
  177. // are notified of pending teardown but before the hierarchy
  178. // is actually torn down.
  179. WindowTreeHost* host = GetHost();
  180. if (host)
  181. host->dispatcher()->OnPostNotifiedWindowDestroying(this);
  182. // The window should have already had its state cleaned up in
  183. // WindowEventDispatcher::OnWindowHidden(), but there have been some crashes
  184. // involving windows being destroyed without being hidden first. See
  185. // crbug.com/342040. This should help us debug the issue. TODO(tdresser):
  186. // remove this once we determine why we have windows that are destroyed
  187. // without being hidden.
  188. bool window_incorrectly_cleaned_up = CleanupGestureState();
  189. CHECK(!window_incorrectly_cleaned_up);
  190. // Then destroy the children.
  191. RemoveOrDestroyChildren();
  192. // The window needs to be removed from the parent before calling the
  193. // WindowDestroyed callbacks of delegate and the observers.
  194. if (parent_)
  195. parent_->RemoveChild(this);
  196. if (delegate_)
  197. delegate_->OnWindowDestroyed(this);
  198. for (WindowObserver& observer : observers_) {
  199. RemoveObserver(&observer);
  200. observer.OnWindowDestroyed(this);
  201. }
  202. // Delete the LayoutManager before properties. This way if the LayoutManager
  203. // depends upon properties existing the properties are still valid.
  204. layout_manager_.reset();
  205. ClearProperties();
  206. // The layer will either be destroyed by |layer_owner_|'s dtor, or by whoever
  207. // acquired it.
  208. layer()->set_delegate(nullptr);
  209. DestroyLayer();
  210. // If SetEmbedFrameSinkId() was called by client code, then we assume client
  211. // code is taking care of invalidating.
  212. if (frame_sink_id_.is_valid() && !embeds_external_client_) {
  213. auto* context_factory = Env::GetInstance()->context_factory();
  214. auto* host_frame_sink_manager = context_factory->GetHostFrameSinkManager();
  215. host_frame_sink_manager->InvalidateFrameSinkId(frame_sink_id_);
  216. }
  217. }
  218. void Window::Init(ui::LayerType layer_type) {
  219. WindowOcclusionTracker::ScopedPause pause_occlusion_tracking;
  220. SetLayer(std::make_unique<ui::Layer>(layer_type));
  221. layer()->SetVisible(false);
  222. layer()->set_delegate(this);
  223. UpdateLayerName();
  224. layer()->SetFillsBoundsOpaquely(!transparent_);
  225. Env::GetInstance()->NotifyWindowInitialized(this);
  226. }
  227. int Window::GetId() const {
  228. return id_;
  229. }
  230. void Window::SetId(int id) {
  231. if (id == id_)
  232. return;
  233. id_ = id;
  234. TriggerChangedCallback(&id_);
  235. }
  236. client::WindowType Window::GetType() const {
  237. return type_;
  238. }
  239. void Window::SetType(client::WindowType type) {
  240. // Cannot change type after the window is initialized.
  241. DCHECK(!layer());
  242. if (type == type_)
  243. return;
  244. type_ = type;
  245. TriggerChangedCallback(&type_);
  246. }
  247. const std::string& Window::GetName() const {
  248. std::string* name = GetProperty(client::kNameKey);
  249. return name ? *name : base::EmptyString();
  250. }
  251. void Window::SetName(const std::string& name) {
  252. if (name == GetName())
  253. return;
  254. SetProperty(client::kNameKey, name);
  255. if (layer())
  256. UpdateLayerName();
  257. TriggerChangedCallback(client::kNameKey);
  258. }
  259. const std::u16string& Window::GetTitle() const {
  260. std::u16string* title = GetProperty(client::kTitleKey);
  261. return title ? *title : base::EmptyString16();
  262. }
  263. void Window::SetTitle(const std::u16string& title) {
  264. if (title == GetTitle())
  265. return;
  266. SetProperty(client::kTitleKey, title);
  267. for (WindowObserver& observer : observers_)
  268. observer.OnWindowTitleChanged(this);
  269. }
  270. bool Window::GetTransparent() const {
  271. return transparent_;
  272. }
  273. void Window::SetTransparent(bool transparent) {
  274. if (transparent == transparent_)
  275. return;
  276. transparent_ = transparent;
  277. if (layer())
  278. layer()->SetFillsBoundsOpaquely(!transparent_);
  279. TriggerChangedCallback(&transparent_);
  280. }
  281. void Window::SetFillsBoundsCompletely(bool fills_bounds) {
  282. layer()->SetFillsBoundsCompletely(fills_bounds);
  283. }
  284. Window* Window::GetRootWindow() {
  285. return const_cast<Window*>(
  286. static_cast<const Window*>(this)->GetRootWindow());
  287. }
  288. const Window* Window::GetRootWindow() const {
  289. return IsRootWindow() ? this : parent_ ? parent_->GetRootWindow() : nullptr;
  290. }
  291. WindowTreeHost* Window::GetHost() {
  292. return const_cast<WindowTreeHost*>(const_cast<const Window*>(this)->
  293. GetHost());
  294. }
  295. const WindowTreeHost* Window::GetHost() const {
  296. const Window* root_window = GetRootWindow();
  297. return root_window ? root_window->host_.get() : nullptr;
  298. }
  299. void Window::Show() {
  300. DCHECK_EQ(visible_, layer()->GetTargetVisibility());
  301. // It is not allowed that a window is visible but the layers alpha is fully
  302. // transparent since the window would still be considered to be active but
  303. // could not be seen.
  304. DCHECK(!visible_ || layer()->GetTargetOpacity() > 0.0f);
  305. SetVisibleInternal(true);
  306. }
  307. void Window::Hide() {
  308. // RootWindow::OnVisibilityChanged will call ReleaseCapture.
  309. SetVisibleInternal(false);
  310. }
  311. bool Window::IsVisible() const {
  312. // Layer visibility can be inconsistent with window visibility, for example
  313. // when a Window is hidden, we want this function to return false immediately
  314. // after, even though the client may decide to animate the hide effect (and
  315. // so the layer will be visible for some time after Hide() is called).
  316. return visible_ ? layer()->IsDrawn() : false;
  317. }
  318. Window::OcclusionState Window::GetOcclusionState() const {
  319. return occlusion_state_;
  320. }
  321. ScopedWindowCaptureRequest Window::MakeWindowCapturable() {
  322. DCHECK(!IsRootWindow()) << "Root windows can already be captured using their "
  323. "FrameSinkId; no need to call this.";
  324. return ScopedWindowCaptureRequest(this);
  325. }
  326. gfx::Rect Window::GetBoundsInRootWindow() const {
  327. if (!GetRootWindow())
  328. return bounds();
  329. gfx::Rect bounds_in_root(bounds().size());
  330. ConvertRectToTarget(this, GetRootWindow(), &bounds_in_root);
  331. return bounds_in_root;
  332. }
  333. gfx::Rect Window::GetActualBoundsInRootWindow() const {
  334. if (!GetRootWindow())
  335. return bounds();
  336. gfx::Rect bounds_in_root(bounds().size());
  337. gfx::PointF origin_f = gfx::PointF(bounds_in_root.origin());
  338. ui::Layer::ConvertPointToLayer(layer(), GetRootWindow()->layer(),
  339. /*use_target_transform=*/false, &origin_f);
  340. bounds_in_root.set_origin(gfx::ToFlooredPoint(origin_f));
  341. return bounds_in_root;
  342. }
  343. const gfx::Transform& Window::transform() const {
  344. return layer()->transform();
  345. }
  346. gfx::Rect Window::GetBoundsInScreen() const {
  347. gfx::Rect bounds(GetBoundsInRootWindow());
  348. const Window* root = GetRootWindow();
  349. if (root) {
  350. aura::client::ScreenPositionClient* screen_position_client =
  351. aura::client::GetScreenPositionClient(root);
  352. if (screen_position_client) {
  353. gfx::Point origin = bounds.origin();
  354. screen_position_client->ConvertPointToScreen(root, &origin);
  355. bounds.set_origin(origin);
  356. }
  357. }
  358. return bounds;
  359. }
  360. gfx::Rect Window::GetActualBoundsInScreen() const {
  361. gfx::Rect bounds(GetActualBoundsInRootWindow());
  362. const Window* root = GetRootWindow();
  363. if (root) {
  364. gfx::Point origin_in_screen = root->GetBoundsInScreen().origin();
  365. origin_in_screen += bounds.OffsetFromOrigin();
  366. bounds.set_origin(origin_in_screen);
  367. }
  368. return bounds;
  369. }
  370. void Window::SetTransform(const gfx::Transform& transform) {
  371. WindowOcclusionTracker::ScopedPause pause_occlusion_tracking;
  372. for (WindowObserver& observer : observers_)
  373. observer.OnWindowTargetTransformChanging(this, transform);
  374. layer()->SetTransform(transform);
  375. }
  376. void Window::SetLayoutManager(LayoutManager* layout_manager) {
  377. if (layout_manager == layout_manager_.get())
  378. return;
  379. layout_manager_.reset(layout_manager);
  380. if (!layout_manager)
  381. return;
  382. // If we're changing to a new layout manager, ensure it is aware of all the
  383. // existing child windows.
  384. for (Windows::const_iterator it = children_.begin();
  385. it != children_.end();
  386. ++it)
  387. layout_manager_->OnWindowAddedToLayout(*it);
  388. }
  389. std::unique_ptr<WindowTargeter> Window::SetEventTargeter(
  390. std::unique_ptr<WindowTargeter> targeter) {
  391. std::unique_ptr<WindowTargeter> old_targeter = std::move(targeter_);
  392. if (old_targeter)
  393. old_targeter->OnInstalled(nullptr);
  394. targeter_ = std::move(targeter);
  395. if (targeter_)
  396. targeter_->OnInstalled(this);
  397. return old_targeter;
  398. }
  399. void Window::SetBounds(const gfx::Rect& new_bounds) {
  400. if (parent_ && parent_->layout_manager()) {
  401. parent_->layout_manager()->SetChildBounds(this, new_bounds);
  402. } else {
  403. // Ensure we don't go smaller than our minimum bounds.
  404. gfx::Rect final_bounds(new_bounds);
  405. if (delegate_) {
  406. const gfx::Size& min_size = delegate_->GetMinimumSize();
  407. final_bounds.set_width(std::max(min_size.width(), final_bounds.width()));
  408. final_bounds.set_height(std::max(min_size.height(),
  409. final_bounds.height()));
  410. }
  411. SetBoundsInternal(final_bounds);
  412. }
  413. }
  414. void Window::SetBoundsInScreen(const gfx::Rect& new_bounds_in_screen,
  415. const display::Display& dst_display) {
  416. aura::client::ScreenPositionClient* screen_position_client = nullptr;
  417. Window* root = GetRootWindow();
  418. if (root)
  419. screen_position_client = aura::client::GetScreenPositionClient(root);
  420. if (screen_position_client)
  421. screen_position_client->SetBounds(this, new_bounds_in_screen, dst_display);
  422. else
  423. SetBounds(new_bounds_in_screen);
  424. }
  425. gfx::Rect Window::GetTargetBounds() const {
  426. return layer() ? layer()->GetTargetBounds() : bounds();
  427. }
  428. void Window::ScheduleDraw() {
  429. layer()->ScheduleDraw();
  430. }
  431. void Window::SchedulePaintInRect(const gfx::Rect& rect) {
  432. layer()->SchedulePaint(rect);
  433. }
  434. void Window::StackChildAtTop(Window* child) {
  435. if (children_.size() <= 1 || child == children_.back())
  436. return; // In the front already.
  437. StackChildAbove(child, children_.back());
  438. }
  439. void Window::StackChildAbove(Window* child, Window* target) {
  440. StackChildRelativeTo(child, target, STACK_ABOVE);
  441. }
  442. void Window::StackChildAtBottom(Window* child) {
  443. if (children_.size() <= 1 || child == children_.front())
  444. return; // At the bottom already.
  445. StackChildBelow(child, children_.front());
  446. }
  447. void Window::StackChildBelow(Window* child, Window* target) {
  448. StackChildRelativeTo(child, target, STACK_BELOW);
  449. }
  450. void Window::AddChild(Window* child) {
  451. WindowOcclusionTracker::ScopedPause pause_occlusion_tracking;
  452. DCHECK(layer()) << "Parent has not been Init()ed yet.";
  453. DCHECK(child->layer()) << "Child has not been Init()ed yt.";
  454. WindowObserver::HierarchyChangeParams params;
  455. params.target = child;
  456. params.new_parent = this;
  457. params.old_parent = child->parent();
  458. params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGING;
  459. NotifyWindowHierarchyChange(params);
  460. Window* old_root = child->GetRootWindow();
  461. DCHECK(!base::Contains(children_, child));
  462. if (child->parent())
  463. child->parent()->RemoveChildImpl(child, this);
  464. child->parent_ = this;
  465. layer()->Add(child->layer());
  466. children_.push_back(child);
  467. if (layout_manager_)
  468. layout_manager_->OnWindowAddedToLayout(child);
  469. for (WindowObserver& observer : observers_)
  470. observer.OnWindowAdded(child);
  471. child->OnParentChanged();
  472. Window* root_window = GetRootWindow();
  473. if (root_window && old_root != root_window) {
  474. root_window->GetHost()->dispatcher()->OnWindowAddedToRootWindow(child);
  475. child->NotifyAddedToRootWindow();
  476. }
  477. params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED;
  478. NotifyWindowHierarchyChange(params);
  479. }
  480. void Window::RemoveChild(Window* child) {
  481. WindowOcclusionTracker::ScopedPause pause_occlusion_tracking;
  482. WindowObserver::HierarchyChangeParams params;
  483. params.target = child;
  484. params.new_parent = nullptr;
  485. params.old_parent = this;
  486. params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGING;
  487. NotifyWindowHierarchyChange(params);
  488. RemoveChildImpl(child, nullptr);
  489. params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED;
  490. NotifyWindowHierarchyChange(params);
  491. }
  492. bool Window::Contains(const Window* other) const {
  493. for (const Window* parent = other; parent; parent = parent->parent_) {
  494. if (parent == this)
  495. return true;
  496. }
  497. return false;
  498. }
  499. Window* Window::GetChildById(int id) {
  500. return const_cast<Window*>(const_cast<const Window*>(this)->GetChildById(id));
  501. }
  502. const Window* Window::GetChildById(int id) const {
  503. Windows::const_iterator i;
  504. for (i = children_.begin(); i != children_.end(); ++i) {
  505. if ((*i)->GetId() == id)
  506. return *i;
  507. const Window* result = (*i)->GetChildById(id);
  508. if (result)
  509. return result;
  510. }
  511. return nullptr;
  512. }
  513. // static
  514. void Window::ConvertPointToTarget(const Window* source,
  515. const Window* target,
  516. gfx::PointF* point) {
  517. if (!source)
  518. return;
  519. if (source->GetRootWindow() != target->GetRootWindow()) {
  520. client::ScreenPositionClient* source_client =
  521. client::GetScreenPositionClient(source->GetRootWindow());
  522. // |source_client| can be nullptr in tests.
  523. if (source_client)
  524. source_client->ConvertPointToScreen(source, point);
  525. client::ScreenPositionClient* target_client =
  526. client::GetScreenPositionClient(target->GetRootWindow());
  527. // |target_client| can be nullptr in tests.
  528. if (target_client)
  529. target_client->ConvertPointFromScreen(target, point);
  530. } else {
  531. ui::Layer::ConvertPointToLayer(source->layer(), target->layer(),
  532. /*use_target_transform=*/true, point);
  533. }
  534. }
  535. // static
  536. void Window::ConvertPointToTarget(const Window* source,
  537. const Window* target,
  538. gfx::Point* point) {
  539. gfx::PointF point_float(*point);
  540. ConvertPointToTarget(source, target, &point_float);
  541. *point = gfx::ToFlooredPoint(point_float);
  542. }
  543. // static
  544. void Window::ConvertRectToTarget(const Window* source,
  545. const Window* target,
  546. gfx::Rect* rect) {
  547. DCHECK(rect);
  548. gfx::Point origin = rect->origin();
  549. ConvertPointToTarget(source, target, &origin);
  550. rect->set_origin(origin);
  551. }
  552. // static
  553. void Window::ConvertNativePointToTargetHost(const Window* source,
  554. const Window* target,
  555. gfx::PointF* point) {
  556. if (!source || !target)
  557. return;
  558. if (source->GetHost() == target->GetHost())
  559. return;
  560. point->Offset(-target->GetHost()->GetBoundsInPixels().x(),
  561. -target->GetHost()->GetBoundsInPixels().y());
  562. }
  563. // static
  564. void Window::ConvertNativePointToTargetHost(const Window* source,
  565. const Window* target,
  566. gfx::Point* point) {
  567. gfx::PointF point_float(*point);
  568. ConvertNativePointToTargetHost(source, target, &point_float);
  569. *point = gfx::ToFlooredPoint(point_float);
  570. }
  571. void Window::MoveCursorTo(const gfx::Point& point_in_window) {
  572. Window* root_window = GetRootWindow();
  573. DCHECK(root_window);
  574. gfx::Point point_in_root(point_in_window);
  575. ConvertPointToTarget(this, root_window, &point_in_root);
  576. root_window->GetHost()->MoveCursorToLocationInDIP(point_in_root);
  577. }
  578. gfx::NativeCursor Window::GetCursor(const gfx::Point& point) const {
  579. return delegate_ ? delegate_->GetCursor(point) : gfx::kNullCursor;
  580. }
  581. void Window::AddObserver(WindowObserver* observer) {
  582. observers_.AddObserver(observer);
  583. }
  584. void Window::RemoveObserver(WindowObserver* observer) {
  585. observers_.RemoveObserver(observer);
  586. }
  587. bool Window::HasObserver(const WindowObserver* observer) const {
  588. return observers_.HasObserver(observer);
  589. }
  590. void Window::SetEventTargetingPolicy(EventTargetingPolicy policy) {
  591. // If the event targeting is blocked on the window, do not allow change event
  592. // targeting policy until all event targeting blockers are removed from the
  593. // window.
  594. if (event_targeting_blocker_count_ > 0) {
  595. restore_event_targeting_policy_ = policy;
  596. return;
  597. }
  598. #if DCHECK_IS_ON()
  599. const bool old_window_accepts_events =
  600. (event_targeting_policy_ == EventTargetingPolicy::kTargetOnly) ||
  601. (event_targeting_policy_ == EventTargetingPolicy::kTargetAndDescendants);
  602. const bool new_window_accepts_events =
  603. (policy == EventTargetingPolicy::kTargetOnly) ||
  604. (policy == EventTargetingPolicy::kTargetAndDescendants);
  605. if (new_window_accepts_events != old_window_accepts_events)
  606. DCHECK(!created_layer_tree_frame_sink_);
  607. #endif
  608. if (event_targeting_policy_ == policy)
  609. return;
  610. event_targeting_policy_ = policy;
  611. layer()->SetAcceptEvents(policy != EventTargetingPolicy::kNone);
  612. }
  613. bool Window::ContainsPointInRoot(const gfx::Point& point_in_root) const {
  614. const Window* root_window = GetRootWindow();
  615. if (!root_window)
  616. return false;
  617. gfx::Point local_point(point_in_root);
  618. ConvertPointToTarget(root_window, this, &local_point);
  619. return gfx::Rect(GetTargetBounds().size()).Contains(local_point);
  620. }
  621. bool Window::ContainsPoint(const gfx::Point& local_point) const {
  622. return gfx::Rect(bounds().size()).Contains(local_point);
  623. }
  624. Window* Window::GetEventHandlerForPoint(const gfx::Point& local_point) {
  625. if (!IsVisible())
  626. return nullptr;
  627. if (!HitTest(local_point))
  628. return nullptr;
  629. for (Window* child : base::Reversed(children_)) {
  630. if (child->event_targeting_policy_ == EventTargetingPolicy::kNone) {
  631. continue;
  632. }
  633. // The client may not allow events to be processed by certain subtrees.
  634. client::EventClient* client = client::GetEventClient(GetRootWindow());
  635. if (client && !client->GetCanProcessEventsWithinSubtree(child))
  636. continue;
  637. if (delegate_ && !delegate_->ShouldDescendIntoChildForEventHandling(
  638. child, local_point)) {
  639. continue;
  640. }
  641. gfx::Point point_in_child_coords(local_point);
  642. ConvertPointToTarget(this, child, &point_in_child_coords);
  643. Window* match = child->GetEventHandlerForPoint(point_in_child_coords);
  644. if (!match)
  645. continue;
  646. switch (child->event_targeting_policy_) {
  647. case EventTargetingPolicy::kTargetOnly:
  648. if (child->delegate_)
  649. return child;
  650. break;
  651. case EventTargetingPolicy::kTargetAndDescendants:
  652. return match;
  653. case EventTargetingPolicy::kDescendantsOnly:
  654. if (match != child)
  655. return match;
  656. break;
  657. case EventTargetingPolicy::kNone:
  658. NOTREACHED(); // This case is handled early on.
  659. }
  660. }
  661. return delegate_ ? this : nullptr;
  662. }
  663. Window* Window::GetToplevelWindow() {
  664. Window* topmost_window_with_delegate = nullptr;
  665. for (aura::Window* window = this; window != nullptr;
  666. window = window->parent()) {
  667. if (window->delegate())
  668. topmost_window_with_delegate = window;
  669. }
  670. return topmost_window_with_delegate;
  671. }
  672. void Window::Focus() {
  673. client::FocusClient* client = client::GetFocusClient(this);
  674. DCHECK(client);
  675. client->FocusWindow(this);
  676. }
  677. bool Window::HasFocus() const {
  678. client::FocusClient* client = client::GetFocusClient(this);
  679. return client && client->GetFocusedWindow() == this;
  680. }
  681. bool Window::CanFocus() const {
  682. if (IsRootWindow())
  683. return IsVisible();
  684. // NOTE: as part of focusing the window the ActivationClient may make the
  685. // window visible (by way of making a hidden ancestor visible). For this
  686. // reason we can't check visibility here and assume the client is doing it.
  687. if (!parent_ || (delegate_ && !delegate_->CanFocus()))
  688. return false;
  689. // The client may forbid certain windows from receiving focus at a given point
  690. // in time.
  691. client::EventClient* client = client::GetEventClient(GetRootWindow());
  692. if (client && !client->GetCanProcessEventsWithinSubtree(this))
  693. return false;
  694. return parent_->CanFocus();
  695. }
  696. void Window::SetCapture() {
  697. if (!IsVisible())
  698. return;
  699. Window* root_window = GetRootWindow();
  700. if (!root_window)
  701. return;
  702. client::CaptureClient* capture_client = client::GetCaptureClient(root_window);
  703. if (!capture_client)
  704. return;
  705. capture_client->SetCapture(this);
  706. }
  707. void Window::ReleaseCapture() {
  708. Window* root_window = GetRootWindow();
  709. if (!root_window)
  710. return;
  711. client::CaptureClient* capture_client = client::GetCaptureClient(root_window);
  712. if (!capture_client)
  713. return;
  714. capture_client->ReleaseCapture(this);
  715. }
  716. bool Window::HasCapture() {
  717. Window* root_window = GetRootWindow();
  718. if (!root_window)
  719. return false;
  720. client::CaptureClient* capture_client = client::GetCaptureClient(root_window);
  721. return capture_client && capture_client->GetCaptureWindow() == this;
  722. }
  723. std::unique_ptr<ScopedKeyboardHook> Window::CaptureSystemKeyEvents(
  724. absl::optional<base::flat_set<ui::DomCode>> dom_codes) {
  725. Window* root_window = GetRootWindow();
  726. if (!root_window)
  727. return nullptr;
  728. WindowTreeHost* host = root_window->GetHost();
  729. if (!host)
  730. return nullptr;
  731. return host->CaptureSystemKeyEvents(std::move(dom_codes));
  732. }
  733. // {Set,Get,Clear}Property are implemented in class_property.h.
  734. void Window::SetNativeWindowProperty(const char* key, void* value) {
  735. SetPropertyInternal(key, key, nullptr, reinterpret_cast<int64_t>(value), 0);
  736. }
  737. void* Window::GetNativeWindowProperty(const char* key) const {
  738. return reinterpret_cast<void*>(GetPropertyInternal(key, 0,
  739. /*search_parent=*/false));
  740. }
  741. void Window::OnDeviceScaleFactorChanged(float old_device_scale_factor,
  742. float new_device_scale_factor) {
  743. if (!IsRootWindow() && last_device_scale_factor_ != new_device_scale_factor &&
  744. IsEmbeddingExternalContent()) {
  745. last_device_scale_factor_ = new_device_scale_factor;
  746. parent_local_surface_id_allocator_->GenerateId();
  747. if (frame_sink_)
  748. frame_sink_->SetLocalSurfaceId(GetCurrentLocalSurfaceId());
  749. }
  750. ScopedCursorHider hider(this);
  751. if (delegate_) {
  752. delegate_->OnDeviceScaleFactorChanged(old_device_scale_factor,
  753. new_device_scale_factor);
  754. }
  755. }
  756. void Window::UpdateVisualState() {
  757. if (delegate_)
  758. delegate_->UpdateVisualState();
  759. }
  760. #if DCHECK_IS_ON()
  761. std::string Window::GetDebugInfo() const {
  762. std::string name = GetName();
  763. if (name.empty())
  764. name = "Unknown";
  765. std::string layer_state = "NoLayer";
  766. if (layer()) {
  767. layer_state = base::StringPrintf(
  768. "%s opacity=%.1f",
  769. layer()->GetTargetVisibility() ? "LayerVisible" : "LayerHidden",
  770. layer()->opacity());
  771. }
  772. return base::StringPrintf(
  773. "%s<%d> bounds=%s %s %s occlusion_state=%s", name.c_str(), GetId(),
  774. bounds().ToString().c_str(), visible_ ? "WindowVisible" : "WindowHidden",
  775. layer_state.c_str(),
  776. base::UTF16ToUTF8(OcclusionStateToString(occlusion_state_)).c_str());
  777. }
  778. std::string Window::GetWindowHierarchy(int depth) const {
  779. std::string hierarchy =
  780. base::StringPrintf("%*s%s\n", depth * 2, "", GetDebugInfo().c_str());
  781. for (Window* child : children_)
  782. hierarchy += child->GetWindowHierarchy(depth + 1);
  783. return hierarchy;
  784. }
  785. void Window::PrintWindowHierarchy(int depth) const {
  786. VLOG(0) << GetWindowHierarchy(depth);
  787. }
  788. #endif
  789. void Window::RemoveOrDestroyChildren() {
  790. while (!children_.empty()) {
  791. Window* child = children_[0];
  792. if (child->owned_by_parent_) {
  793. delete child;
  794. // Deleting the child so remove it from out children_ list.
  795. DCHECK(!base::Contains(children_, child));
  796. } else {
  797. // Even if we can't delete the child, we still need to remove it from the
  798. // parent so that relevant bookkeeping (parent_ back-pointers etc) are
  799. // updated.
  800. RemoveChild(child);
  801. }
  802. }
  803. }
  804. void Window::AfterPropertyChange(const void* key, int64_t old_value) {
  805. for (WindowObserver& observer : observers_)
  806. observer.OnWindowPropertyChanged(this, key, old_value);
  807. }
  808. ///////////////////////////////////////////////////////////////////////////////
  809. // Window, private:
  810. void Window::SetEmbedFrameSinkIdImpl(const viz::FrameSinkId& frame_sink_id) {
  811. UnregisterFrameSinkId();
  812. DCHECK(frame_sink_id.is_valid());
  813. frame_sink_id_ = frame_sink_id;
  814. RegisterFrameSinkId();
  815. }
  816. bool Window::HitTest(const gfx::Point& local_point) {
  817. gfx::Rect local_bounds(bounds().size());
  818. if (!delegate_ || !delegate_->HasHitTestMask())
  819. return local_bounds.Contains(local_point);
  820. SkPath mask;
  821. delegate_->GetHitTestMask(&mask);
  822. SkRegion clip_region;
  823. clip_region.setRect({local_bounds.x(), local_bounds.y(), local_bounds.width(),
  824. local_bounds.height()});
  825. SkRegion mask_region;
  826. return mask_region.setPath(mask, clip_region) &&
  827. mask_region.contains(local_point.x(), local_point.y());
  828. }
  829. void Window::SetBoundsInternal(const gfx::Rect& new_bounds) {
  830. gfx::Rect old_bounds = GetTargetBounds();
  831. // Always need to set the layer's bounds -- even if it is to the same thing.
  832. // This may cause important side effects such as stopping animation.
  833. layer()->SetBounds(new_bounds);
  834. // If we are currently not the layer's delegate, we will not get bounds
  835. // changed notification from the layer (this typically happens after animating
  836. // hidden). We must notify ourselves.
  837. if (layer()->delegate() != this) {
  838. OnLayerBoundsChanged(old_bounds,
  839. ui::PropertyChangeReason::NOT_FROM_ANIMATION);
  840. }
  841. }
  842. void Window::SetVisibleInternal(bool visible) {
  843. if (visible == layer()->GetTargetVisibility())
  844. return; // No change.
  845. WindowOcclusionTracker::ScopedPause pause_occlusion_tracking;
  846. for (WindowObserver& observer : observers_)
  847. observer.OnWindowVisibilityChanging(this, visible);
  848. client::VisibilityClient* visibility_client =
  849. client::GetVisibilityClient(this);
  850. if (visibility_client)
  851. visibility_client->UpdateLayerVisibility(this, visible);
  852. else
  853. layer()->SetVisible(visible);
  854. visible_ = visible;
  855. SchedulePaint();
  856. if (parent_ && parent_->layout_manager_)
  857. parent_->layout_manager_->OnChildWindowVisibilityChanged(this, visible);
  858. if (delegate_)
  859. delegate_->OnWindowTargetVisibilityChanged(visible);
  860. NotifyWindowVisibilityChanged(this, visible);
  861. }
  862. void Window::SetOcclusionInfo(OcclusionState occlusion_state,
  863. const SkRegion& occluded_region) {
  864. if (occlusion_state == occlusion_state_ &&
  865. occluded_region_in_root_ == occluded_region) {
  866. return;
  867. }
  868. occlusion_state_ = occlusion_state;
  869. occluded_region_in_root_ = occluded_region;
  870. if (delegate_)
  871. delegate_->OnWindowOcclusionChanged(occlusion_state);
  872. for (WindowObserver& observer : observers_)
  873. observer.OnWindowOcclusionChanged(this);
  874. }
  875. void Window::SchedulePaint() {
  876. SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height()));
  877. }
  878. void Window::Paint(const ui::PaintContext& context) {
  879. if (delegate_)
  880. delegate_->OnPaint(context);
  881. }
  882. void Window::RemoveChildImpl(Window* child, Window* new_parent) {
  883. if (layout_manager_)
  884. layout_manager_->OnWillRemoveWindowFromLayout(child);
  885. for (WindowObserver& observer : observers_)
  886. observer.OnWillRemoveWindow(child);
  887. Window* root_window = child->GetRootWindow();
  888. Window* new_root_window = new_parent ? new_parent->GetRootWindow() : nullptr;
  889. if (root_window && root_window != new_root_window)
  890. child->NotifyRemovingFromRootWindow(new_root_window);
  891. if (child->OwnsLayer())
  892. layer()->Remove(child->layer());
  893. child->parent_ = nullptr;
  894. auto i = std::find(children_.begin(), children_.end(), child);
  895. DCHECK(i != children_.end());
  896. children_.erase(i);
  897. child->OnParentChanged();
  898. if (layout_manager_)
  899. layout_manager_->OnWindowRemovedFromLayout(child);
  900. for (WindowObserver& observer : observers_)
  901. observer.OnWindowRemoved(child);
  902. }
  903. void Window::OnParentChanged() {
  904. for (WindowObserver& observer : observers_)
  905. observer.OnWindowParentChanged(this, parent_);
  906. }
  907. void Window::StackChildRelativeTo(Window* child,
  908. Window* target,
  909. StackDirection direction) {
  910. DCHECK_NE(child, target);
  911. DCHECK(child);
  912. DCHECK(target);
  913. DCHECK_EQ(this, child->parent());
  914. DCHECK_EQ(this, target->parent());
  915. WindowOcclusionTracker::ScopedPause pause_occlusion_tracking;
  916. client::WindowStackingClient* stacking_client =
  917. client::GetWindowStackingClient();
  918. if (stacking_client &&
  919. !stacking_client->AdjustStacking(&child, &target, &direction))
  920. return;
  921. const size_t child_i =
  922. std::find(children_.begin(), children_.end(), child) - children_.begin();
  923. const size_t target_i =
  924. std::find(children_.begin(), children_.end(), target) - children_.begin();
  925. DCHECK_LT(child_i, children_.size()) << "Child was not in list of children!";
  926. DCHECK_LT(target_i, children_.size())
  927. << "Target was not in list of children!";
  928. // Don't move the child if it is already in the right place.
  929. if ((direction == STACK_ABOVE && child_i == target_i + 1) ||
  930. (direction == STACK_BELOW && child_i + 1 == target_i))
  931. return;
  932. const size_t dest_i =
  933. direction == STACK_ABOVE ?
  934. (child_i < target_i ? target_i : target_i + 1) :
  935. (child_i < target_i ? target_i - 1 : target_i);
  936. children_.erase(children_.begin() + child_i);
  937. children_.insert(children_.begin() + dest_i, child);
  938. StackChildLayerRelativeTo(child, target, direction);
  939. child->OnStackingChanged();
  940. }
  941. void Window::StackChildLayerRelativeTo(Window* child,
  942. Window* target,
  943. StackDirection direction) {
  944. DCHECK(layer() && child->layer() && target->layer());
  945. if (direction == STACK_ABOVE)
  946. layer()->StackAbove(child->layer(), target->layer());
  947. else
  948. layer()->StackBelow(child->layer(), target->layer());
  949. }
  950. void Window::OnStackingChanged() {
  951. for (WindowObserver& observer : observers_)
  952. observer.OnWindowStackingChanged(this);
  953. }
  954. void Window::NotifyRemovingFromRootWindow(Window* new_root) {
  955. if (frame_sink_id_.is_valid())
  956. UnregisterFrameSinkId();
  957. for (WindowObserver& observer : observers_)
  958. observer.OnWindowRemovingFromRootWindow(this, new_root);
  959. for (Window::Windows::const_iterator it = children_.begin();
  960. it != children_.end(); ++it) {
  961. (*it)->NotifyRemovingFromRootWindow(new_root);
  962. }
  963. }
  964. void Window::NotifyAddedToRootWindow() {
  965. if (frame_sink_id_.is_valid())
  966. RegisterFrameSinkId();
  967. for (WindowObserver& observer : observers_)
  968. observer.OnWindowAddedToRootWindow(this);
  969. for (Window::Windows::const_iterator it = children_.begin();
  970. it != children_.end(); ++it) {
  971. (*it)->NotifyAddedToRootWindow();
  972. }
  973. }
  974. void Window::NotifyWindowHierarchyChange(
  975. const WindowObserver::HierarchyChangeParams& params) {
  976. params.target->NotifyWindowHierarchyChangeDown(params);
  977. switch (params.phase) {
  978. case WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGING:
  979. if (params.old_parent)
  980. params.old_parent->NotifyWindowHierarchyChangeUp(params);
  981. break;
  982. case WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED:
  983. if (params.new_parent)
  984. params.new_parent->NotifyWindowHierarchyChangeUp(params);
  985. break;
  986. }
  987. }
  988. void Window::NotifyWindowHierarchyChangeDown(
  989. const WindowObserver::HierarchyChangeParams& params) {
  990. NotifyWindowHierarchyChangeAtReceiver(params);
  991. for (Window::Windows::const_iterator it = children_.begin();
  992. it != children_.end(); ++it) {
  993. (*it)->NotifyWindowHierarchyChangeDown(params);
  994. }
  995. }
  996. void Window::NotifyWindowHierarchyChangeUp(
  997. const WindowObserver::HierarchyChangeParams& params) {
  998. for (Window* window = this; window; window = window->parent())
  999. window->NotifyWindowHierarchyChangeAtReceiver(params);
  1000. }
  1001. void Window::NotifyWindowHierarchyChangeAtReceiver(
  1002. const WindowObserver::HierarchyChangeParams& params) {
  1003. WindowObserver::HierarchyChangeParams local_params = params;
  1004. local_params.receiver = this;
  1005. switch (params.phase) {
  1006. case WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGING:
  1007. for (WindowObserver& observer : observers_)
  1008. observer.OnWindowHierarchyChanging(local_params);
  1009. break;
  1010. case WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED:
  1011. for (WindowObserver& observer : observers_)
  1012. observer.OnWindowHierarchyChanged(local_params);
  1013. break;
  1014. }
  1015. }
  1016. void Window::NotifyWindowVisibilityChanged(aura::Window* target,
  1017. bool visible) {
  1018. if (!NotifyWindowVisibilityChangedDown(target, visible))
  1019. return; // |this| has been deleted.
  1020. NotifyWindowVisibilityChangedUp(target, visible);
  1021. }
  1022. bool Window::NotifyWindowVisibilityChangedAtReceiver(aura::Window* target,
  1023. bool visible) {
  1024. // |this| may be deleted during a call to OnWindowVisibilityChanged() on one
  1025. // of the observers. We create an local observer for that. In that case we
  1026. // exit without further access to any members.
  1027. WindowTracker tracker;
  1028. tracker.Add(this);
  1029. for (WindowObserver& observer : observers_)
  1030. observer.OnWindowVisibilityChanged(target, visible);
  1031. return tracker.Contains(this);
  1032. }
  1033. bool Window::NotifyWindowVisibilityChangedDown(aura::Window* target,
  1034. bool visible) {
  1035. if (!NotifyWindowVisibilityChangedAtReceiver(target, visible))
  1036. return false; // |this| was deleted.
  1037. WindowTracker this_tracker;
  1038. this_tracker.Add(this);
  1039. // Copy |children_| in case iterating mutates |children_|, or destroys an
  1040. // existing child.
  1041. WindowTracker children(children_);
  1042. while (!this_tracker.windows().empty() && !children.windows().empty())
  1043. children.Pop()->NotifyWindowVisibilityChangedDown(target, visible);
  1044. const bool this_still_valid = !this_tracker.windows().empty();
  1045. return this_still_valid;
  1046. }
  1047. void Window::NotifyWindowVisibilityChangedUp(aura::Window* target,
  1048. bool visible) {
  1049. // Start with the parent as we already notified |this|
  1050. // in NotifyWindowVisibilityChangedDown.
  1051. for (Window* window = parent(); window; window = window->parent()) {
  1052. bool ret = window->NotifyWindowVisibilityChangedAtReceiver(target, visible);
  1053. DCHECK(ret);
  1054. }
  1055. }
  1056. bool Window::CleanupGestureState() {
  1057. // If it's in the process already, nothing has to be done. Reentrant can
  1058. // happen through some event handlers for CancelActiveTouches().
  1059. if (cleaning_up_gesture_state_)
  1060. return false;
  1061. cleaning_up_gesture_state_ = true;
  1062. // Cancelling active touches may end up destroying this window. We use a
  1063. // tracker to detect this.
  1064. WindowTracker tracking_this({this});
  1065. bool state_modified = false;
  1066. Env* env = Env::GetInstance();
  1067. state_modified |= env->gesture_recognizer()->CancelActiveTouches(this);
  1068. state_modified |= env->gesture_recognizer()->CleanupStateForConsumer(this);
  1069. if (!tracking_this.Contains(this))
  1070. return state_modified;
  1071. // Potentially event handlers for CancelActiveTouches() within
  1072. // CleanupGestureState may change the window hierarchy (or reorder the
  1073. // |children_|), and therefore iterating over |children_| is not safe. Use
  1074. // WindowTracker to track the list of children.
  1075. WindowTracker children(children_);
  1076. while (!children.windows().empty()) {
  1077. Window* child = children.Pop();
  1078. state_modified |= child->CleanupGestureState();
  1079. }
  1080. cleaning_up_gesture_state_ = false;
  1081. return state_modified;
  1082. }
  1083. std::unique_ptr<cc::LayerTreeFrameSink> Window::CreateLayerTreeFrameSink() {
  1084. // Currently we don't have a need for both SetEmbedFrameSinkId() and
  1085. // this function be called.
  1086. DCHECK(!embeds_external_client_);
  1087. auto* context_factory = Env::GetInstance()->context_factory();
  1088. auto* host_frame_sink_manager = context_factory->GetHostFrameSinkManager();
  1089. if (!frame_sink_id_.is_valid()) {
  1090. auto frame_sink_id = context_factory->AllocateFrameSinkId();
  1091. host_frame_sink_manager->RegisterFrameSinkId(
  1092. frame_sink_id, this, viz::ReportFirstSurfaceActivation::kYes);
  1093. SetEmbedFrameSinkIdImpl(frame_sink_id);
  1094. }
  1095. // For creating a async frame sink which connects to the viz display
  1096. // compositor.
  1097. mojo::PendingRemote<viz::mojom::CompositorFrameSink> sink_remote;
  1098. mojo::PendingReceiver<viz::mojom::CompositorFrameSink> sink_receiver =
  1099. sink_remote.InitWithNewPipeAndPassReceiver();
  1100. mojo::PendingRemote<viz::mojom::CompositorFrameSinkClient> client_remote;
  1101. mojo::PendingReceiver<viz::mojom::CompositorFrameSinkClient> client_receiver =
  1102. client_remote.InitWithNewPipeAndPassReceiver();
  1103. host_frame_sink_manager->CreateCompositorFrameSink(
  1104. frame_sink_id_, std::move(sink_receiver), std::move(client_remote));
  1105. cc::mojo_embedder::AsyncLayerTreeFrameSink::InitParams params;
  1106. params.gpu_memory_buffer_manager =
  1107. Env::GetInstance()->context_factory()->GetGpuMemoryBufferManager();
  1108. params.pipes.compositor_frame_sink_remote = std::move(sink_remote);
  1109. params.pipes.client_receiver = std::move(client_receiver);
  1110. params.client_name = kExo;
  1111. auto frame_sink =
  1112. std::make_unique<cc::mojo_embedder::AsyncLayerTreeFrameSink>(
  1113. nullptr /* context_provider */, nullptr /* worker_context_provider */,
  1114. &params);
  1115. frame_sink_ = frame_sink->GetWeakPtr();
  1116. AllocateLocalSurfaceId();
  1117. DCHECK(GetLocalSurfaceId().is_valid());
  1118. #if DCHECK_IS_ON()
  1119. created_layer_tree_frame_sink_ = true;
  1120. #endif
  1121. return std::move(frame_sink);
  1122. }
  1123. viz::SurfaceId Window::GetSurfaceId() {
  1124. return viz::SurfaceId(GetFrameSinkId(), GetLocalSurfaceId());
  1125. }
  1126. viz::SurfaceId Window::GetSurfaceId() const {
  1127. return const_cast<Window*>(this)->GetSurfaceId();
  1128. }
  1129. void Window::AllocateLocalSurfaceId() {
  1130. if (!parent_local_surface_id_allocator_) {
  1131. parent_local_surface_id_allocator_ =
  1132. std::make_unique<viz::ParentLocalSurfaceIdAllocator>();
  1133. }
  1134. parent_local_surface_id_allocator_->GenerateId();
  1135. UpdateLocalSurfaceId();
  1136. }
  1137. viz::ScopedSurfaceIdAllocator Window::GetSurfaceIdAllocator(
  1138. base::OnceCallback<void()> allocation_task) {
  1139. return viz::ScopedSurfaceIdAllocator(parent_local_surface_id_allocator_.get(),
  1140. std::move(allocation_task));
  1141. }
  1142. const viz::LocalSurfaceId& Window::GetLocalSurfaceId() {
  1143. if (!parent_local_surface_id_allocator_)
  1144. AllocateLocalSurfaceId();
  1145. return GetCurrentLocalSurfaceId();
  1146. }
  1147. void Window::InvalidateLocalSurfaceId() {
  1148. if (!parent_local_surface_id_allocator_)
  1149. return;
  1150. parent_local_surface_id_allocator_->Invalidate();
  1151. }
  1152. void Window::UpdateLocalSurfaceIdFromEmbeddedClient(
  1153. const absl::optional<viz::LocalSurfaceId>&
  1154. embedded_client_local_surface_id) {
  1155. if (embedded_client_local_surface_id) {
  1156. parent_local_surface_id_allocator_->UpdateFromChild(
  1157. *embedded_client_local_surface_id);
  1158. UpdateLocalSurfaceId();
  1159. } else {
  1160. AllocateLocalSurfaceId();
  1161. }
  1162. }
  1163. const viz::FrameSinkId& Window::GetFrameSinkId() const {
  1164. if (IsRootWindow()) {
  1165. DCHECK(host_);
  1166. auto* compositor = host_->compositor();
  1167. DCHECK(compositor);
  1168. return compositor->frame_sink_id();
  1169. }
  1170. return frame_sink_id_;
  1171. }
  1172. void Window::SetEmbedFrameSinkId(const viz::FrameSinkId& frame_sink_id) {
  1173. SetEmbedFrameSinkIdImpl(frame_sink_id);
  1174. embeds_external_client_ = true;
  1175. }
  1176. void Window::TrackOcclusionState() {
  1177. Env::GetInstance()->GetWindowOcclusionTracker()->Track(this);
  1178. }
  1179. bool Window::RequiresDoubleTapGestureEvents() const {
  1180. return delegate_ && delegate_->RequiresDoubleTapGestureEvents();
  1181. }
  1182. // static
  1183. const std::u16string Window::OcclusionStateToString(OcclusionState state) {
  1184. return ui::metadata::TypeConverter<OcclusionState>::ToString(state);
  1185. }
  1186. void Window::SetOpaqueRegionsForOcclusion(
  1187. const std::vector<gfx::Rect>& opaque_regions_for_occlusion) {
  1188. // Only transparent windows should try to set opaque regions for occlusion.
  1189. DCHECK(GetTransparent() || opaque_regions_for_occlusion.empty());
  1190. if (opaque_regions_for_occlusion == opaque_regions_for_occlusion_)
  1191. return;
  1192. opaque_regions_for_occlusion_ = opaque_regions_for_occlusion;
  1193. for (auto& observer : observers_)
  1194. observer.OnWindowOpaqueRegionsForOcclusionChanged(this);
  1195. }
  1196. void Window::NotifyResizeLoopStarted() {
  1197. for (auto& observer : observers_)
  1198. observer.OnResizeLoopStarted(this);
  1199. }
  1200. void Window::NotifyResizeLoopEnded() {
  1201. for (auto& observer : observers_)
  1202. observer.OnResizeLoopEnded(this);
  1203. }
  1204. void Window::OnPaintLayer(const ui::PaintContext& context) {
  1205. Paint(context);
  1206. }
  1207. void Window::OnLayerBoundsChanged(const gfx::Rect& old_bounds,
  1208. ui::PropertyChangeReason reason) {
  1209. WindowOcclusionTracker::ScopedPause pause_occlusion_tracking;
  1210. bounds_ = layer()->bounds();
  1211. if (!IsRootWindow() && old_bounds.size() != bounds_.size() &&
  1212. IsEmbeddingExternalContent()) {
  1213. parent_local_surface_id_allocator_->GenerateId();
  1214. if (frame_sink_) {
  1215. frame_sink_->SetLocalSurfaceId(GetCurrentLocalSurfaceId());
  1216. }
  1217. }
  1218. if (layout_manager_)
  1219. layout_manager_->OnWindowResized();
  1220. if (delegate_)
  1221. delegate_->OnBoundsChanged(old_bounds, bounds_);
  1222. for (auto& observer : observers_)
  1223. observer.OnWindowBoundsChanged(this, old_bounds, bounds_, reason);
  1224. // Trigger the changed notification for each of the bounds "properties".
  1225. if (old_bounds.x() != bounds_.x())
  1226. TriggerChangedCallback(&bounds_ + kBoundsX);
  1227. if (old_bounds.y() != bounds_.y())
  1228. TriggerChangedCallback(&bounds_ + kBoundsY);
  1229. if (old_bounds.width() != bounds_.width())
  1230. TriggerChangedCallback(&bounds_ + kBoundsWidth);
  1231. if (old_bounds.height() != bounds_.height())
  1232. TriggerChangedCallback(&bounds_ + kBoundsHeight);
  1233. }
  1234. void Window::OnLayerOpacityChanged(ui::PropertyChangeReason reason) {
  1235. WindowOcclusionTracker::ScopedPause pause_occlusion_tracking;
  1236. for (WindowObserver& observer : observers_)
  1237. observer.OnWindowOpacitySet(this, reason);
  1238. }
  1239. void Window::OnLayerAlphaShapeChanged() {
  1240. WindowOcclusionTracker::ScopedPause pause_occlusion_tracking;
  1241. for (WindowObserver& observer : observers_)
  1242. observer.OnWindowAlphaShapeSet(this);
  1243. }
  1244. void Window::OnLayerFillsBoundsOpaquelyChanged(
  1245. ui::PropertyChangeReason reason) {
  1246. // Let observers know that this window's transparent status has changed.
  1247. // Transparent status can affect the occlusion computed for windows.
  1248. WindowOcclusionTracker::ScopedPause pause_occlusion_tracking;
  1249. // Non-transparent windows should not have opaque regions for occlusion set.
  1250. if (!GetTransparent())
  1251. DCHECK(opaque_regions_for_occlusion_.empty());
  1252. for (WindowObserver& observer : observers_)
  1253. observer.OnWindowTransparentChanged(this, reason);
  1254. }
  1255. void Window::OnLayerTransformed(const gfx::Transform& old_transform,
  1256. ui::PropertyChangeReason reason) {
  1257. WindowOcclusionTracker::ScopedPause pause_occlusion_tracking;
  1258. for (WindowObserver& observer : observers_)
  1259. observer.OnWindowTransformed(this, reason);
  1260. }
  1261. bool Window::CanAcceptEvent(const ui::Event& event) {
  1262. // The client may forbid certain windows from receiving events at a given
  1263. // point in time.
  1264. client::EventClient* client = client::GetEventClient(GetRootWindow());
  1265. if (client && !client->GetCanProcessEventsWithinSubtree(this))
  1266. return false;
  1267. // We need to make sure that a touch cancel event and any gesture events it
  1268. // creates can always reach the window. This ensures that we receive a valid
  1269. // touch / gesture stream.
  1270. if (event.IsEndingEvent())
  1271. return true;
  1272. if (!IsVisible())
  1273. return false;
  1274. // The top-most window can always process an event.
  1275. if (!parent_)
  1276. return true;
  1277. // For located events (i.e. mouse, touch etc.), an assumption is made that
  1278. // windows that don't have a default event-handler cannot process the event
  1279. // (see more in GetWindowForPoint()). This assumption is not made for key
  1280. // events.
  1281. return event.IsKeyEvent() || target_handler();
  1282. }
  1283. ui::EventTarget* Window::GetParentTarget() {
  1284. if (IsRootWindow()) {
  1285. return client::GetEventClient(this)
  1286. ? client::GetEventClient(this)->GetToplevelEventTarget()
  1287. : Env::GetInstance();
  1288. }
  1289. return parent_;
  1290. }
  1291. std::unique_ptr<ui::EventTargetIterator> Window::GetChildIterator() const {
  1292. return std::make_unique<ui::EventTargetIteratorPtrImpl<Window>>(children());
  1293. }
  1294. ui::EventTargeter* Window::GetEventTargeter() {
  1295. return targeter_.get();
  1296. }
  1297. void Window::ConvertEventToTarget(const ui::EventTarget* target,
  1298. ui::LocatedEvent* event) const {
  1299. event->ConvertLocationToTarget(this, static_cast<const Window*>(target));
  1300. }
  1301. gfx::PointF Window::GetScreenLocationF(const ui::LocatedEvent& event) const {
  1302. DCHECK_EQ(this, event.target());
  1303. gfx::PointF screen_location(event.root_location_f());
  1304. const Window* root = GetRootWindow();
  1305. auto* screen_position_client = aura::client::GetScreenPositionClient(root);
  1306. if (screen_position_client)
  1307. screen_position_client->ConvertPointToScreen(root, &screen_location);
  1308. return screen_location;
  1309. }
  1310. std::unique_ptr<ui::Layer> Window::ReleaseLayer() {
  1311. if (number_of_capture_requests_) {
  1312. // Before we release our own layer, if this window was marked for capture,
  1313. // we need to reset the SubtreeCaptureId on that layer as it will no longer
  1314. // be associated with us.
  1315. DCHECK(subtree_capture_id_.is_valid());
  1316. if (layer())
  1317. layer()->SetSubtreeCaptureId(viz::SubtreeCaptureId());
  1318. }
  1319. return LayerOwner::ReleaseLayer();
  1320. }
  1321. std::unique_ptr<ui::Layer> Window::RecreateLayer() {
  1322. WindowOcclusionTracker::ScopedPause pause_occlusion_tracking;
  1323. ui::LayerAnimator* const animator = layer()->GetAnimator();
  1324. const bool was_animating_opacity =
  1325. animator->IsAnimatingProperty(ui::LayerAnimationElement::OPACITY);
  1326. const bool was_animating_transform =
  1327. animator->IsAnimatingProperty(ui::LayerAnimationElement::TRANSFORM);
  1328. std::unique_ptr<ui::Layer> old_layer = LayerOwner::RecreateLayer();
  1329. // If a frame sink is attached to the window, then allocate a new surface
  1330. // id when layers are recreated, so the old layer contents are not affected
  1331. // by a frame sent to the frame sink.
  1332. if (GetFrameSinkId().is_valid() && old_layer)
  1333. AllocateLocalSurfaceId();
  1334. // The old layer subtree must no longer be capturable.
  1335. // Note that we don't need to worry about the newly recreated layer since
  1336. // Window::SetLayer() will have taken care of it already.
  1337. if (number_of_capture_requests_ && old_layer)
  1338. old_layer->SetSubtreeCaptureId(viz::SubtreeCaptureId());
  1339. // Observers are guaranteed to be notified when an opacity or transform
  1340. // animation ends.
  1341. if (was_animating_opacity) {
  1342. for (WindowObserver& observer : observers_) {
  1343. observer.OnWindowOpacitySet(this,
  1344. ui::PropertyChangeReason::FROM_ANIMATION);
  1345. }
  1346. }
  1347. if (was_animating_transform) {
  1348. for (WindowObserver& observer : observers_) {
  1349. observer.OnWindowTransformed(this,
  1350. ui::PropertyChangeReason::FROM_ANIMATION);
  1351. }
  1352. }
  1353. for (WindowObserver& observer : observers_)
  1354. observer.OnWindowLayerRecreated(this);
  1355. return old_layer;
  1356. }
  1357. void Window::SetLayer(std::unique_ptr<ui::Layer> alayer) {
  1358. LayerOwner::SetLayer(std::move(alayer));
  1359. if (number_of_capture_requests_) {
  1360. // If this window was marked for capture before, then the new layer that we
  1361. // own now should be given the current SubtreeCaptureId that we have.
  1362. DCHECK(subtree_capture_id_.is_valid());
  1363. if (layer())
  1364. layer()->SetSubtreeCaptureId(subtree_capture_id_);
  1365. }
  1366. }
  1367. void Window::OnFirstSurfaceActivation(const viz::SurfaceInfo& surface_info) {
  1368. DCHECK_EQ(surface_info.id().frame_sink_id(), GetFrameSinkId());
  1369. layer()->SetShowSurface(surface_info.id(), bounds().size(), SK_ColorWHITE,
  1370. cc::DeadlinePolicy::UseDefaultDeadline(),
  1371. false /* stretch_content_to_fill_bounds */);
  1372. }
  1373. void Window::OnFrameTokenChanged(uint32_t frame_token,
  1374. base::TimeTicks activation_time) {}
  1375. void Window::UpdateLayerName() {
  1376. DCHECK(layer());
  1377. std::string layer_name(GetName());
  1378. if (layer_name.empty())
  1379. layer_name = "Unnamed Window";
  1380. if (id_ != -1)
  1381. layer_name += " " + base::NumberToString(id_);
  1382. layer()->SetName(layer_name);
  1383. }
  1384. void Window::RegisterFrameSinkId() {
  1385. DCHECK(frame_sink_id_.is_valid());
  1386. if (registered_frame_sink_id_ || disable_frame_sink_id_registration_)
  1387. return;
  1388. if (auto* compositor = layer()->GetCompositor()) {
  1389. compositor->AddChildFrameSink(frame_sink_id_);
  1390. registered_frame_sink_id_ = true;
  1391. }
  1392. }
  1393. void Window::UnregisterFrameSinkId() {
  1394. if (!registered_frame_sink_id_)
  1395. return;
  1396. registered_frame_sink_id_ = false;
  1397. if (auto* compositor = layer()->GetCompositor())
  1398. compositor->RemoveChildFrameSink(frame_sink_id_);
  1399. }
  1400. void Window::UpdateLocalSurfaceId() {
  1401. last_device_scale_factor_ = ui::GetScaleFactorForNativeView(this);
  1402. if (frame_sink_) {
  1403. frame_sink_->SetLocalSurfaceId(GetCurrentLocalSurfaceId());
  1404. }
  1405. }
  1406. const viz::LocalSurfaceId& Window::GetCurrentLocalSurfaceId() const {
  1407. return parent_local_surface_id_allocator_->GetCurrentLocalSurfaceId();
  1408. }
  1409. bool Window::IsEmbeddingExternalContent() const {
  1410. return parent_local_surface_id_allocator_.get() != nullptr;
  1411. }
  1412. void Window::OnScopedWindowCaptureRequestAdded() {
  1413. if (++number_of_capture_requests_ == 1) {
  1414. DCHECK(!subtree_capture_id_.is_valid());
  1415. DCHECK(!layer() || !layer()->GetSubtreeCaptureId().is_valid());
  1416. subtree_capture_id_ =
  1417. Env::GetInstance()->context_factory()->AllocateSubtreeCaptureId();
  1418. if (layer())
  1419. layer()->SetSubtreeCaptureId(subtree_capture_id_);
  1420. }
  1421. DCHECK(subtree_capture_id_.is_valid());
  1422. }
  1423. void Window::OnScopedWindowCaptureRequestRemoved() {
  1424. DCHECK(subtree_capture_id_.is_valid());
  1425. DCHECK(number_of_capture_requests_);
  1426. --number_of_capture_requests_;
  1427. DCHECK_GE(number_of_capture_requests_, 0);
  1428. if (number_of_capture_requests_ == 0) {
  1429. subtree_capture_id_ = viz::SubtreeCaptureId();
  1430. if (layer())
  1431. layer()->SetSubtreeCaptureId(subtree_capture_id_);
  1432. }
  1433. }
  1434. int Window::GetHeight() const {
  1435. return bounds().height();
  1436. }
  1437. int Window::GetWidth() const {
  1438. return bounds().width();
  1439. }
  1440. int Window::GetX() const {
  1441. return bounds().x();
  1442. }
  1443. int Window::GetY() const {
  1444. return bounds().y();
  1445. }
  1446. void Window::SetHeight(int height) {
  1447. if (height == bounds().height())
  1448. return;
  1449. // Bounds changed notification is done within OnLayerBoundsChanged.
  1450. // Here and below.
  1451. SetBounds({bounds().x(), bounds().y(), bounds().width(), height});
  1452. }
  1453. void Window::SetWidth(int width) {
  1454. if (width == bounds().width())
  1455. return;
  1456. SetBounds({bounds().x(), bounds().y(), width, bounds().height()});
  1457. }
  1458. void Window::SetX(int x) {
  1459. if (x == bounds().x())
  1460. return;
  1461. SetBounds({x, bounds().y(), bounds().width(), bounds().height()});
  1462. }
  1463. void Window::SetY(int y) {
  1464. if (y == bounds().y())
  1465. return;
  1466. SetBounds({bounds().x(), y, bounds().width(), bounds().height()});
  1467. }
  1468. bool Window::GetCapture() const {
  1469. return const_cast<Window*>(this)->HasCapture();
  1470. }
  1471. bool Window::GetVisible() const {
  1472. return IsVisible();
  1473. }
  1474. void Window::SetVisible(bool visible) {
  1475. if (visible == IsVisible())
  1476. return;
  1477. if (visible)
  1478. Show();
  1479. else
  1480. Hide();
  1481. // Changed notification is handled in SetVisibleInternal().
  1482. }
  1483. BEGIN_METADATA_BASE(Window)
  1484. ADD_READONLY_PROPERTY_METADATA(gfx::Rect, ActualBoundsInRootWindow)
  1485. ADD_READONLY_PROPERTY_METADATA(gfx::Rect, ActualBoundsInScreen)
  1486. ADD_READONLY_PROPERTY_METADATA(gfx::Rect, BoundsInRootWindow)
  1487. ADD_READONLY_PROPERTY_METADATA(gfx::Rect, BoundsInScreen)
  1488. ADD_READONLY_PROPERTY_METADATA(bool, Capture)
  1489. ADD_PROPERTY_METADATA(int, Height)
  1490. ADD_PROPERTY_METADATA(int, Width)
  1491. ADD_PROPERTY_METADATA(int, X)
  1492. ADD_PROPERTY_METADATA(int, Y)
  1493. ADD_READONLY_PROPERTY_METADATA(Window::OcclusionState, OcclusionState)
  1494. ADD_READONLY_PROPERTY_METADATA(viz::SurfaceId, SurfaceId)
  1495. ADD_PROPERTY_METADATA(int, Id)
  1496. ADD_PROPERTY_METADATA(std::string, Name)
  1497. ADD_PROPERTY_METADATA(std::u16string, Title)
  1498. ADD_PROPERTY_METADATA(bool, Transparent)
  1499. ADD_PROPERTY_METADATA(client::WindowType, Type)
  1500. ADD_PROPERTY_METADATA(bool, Visible)
  1501. END_METADATA
  1502. } // namespace aura