| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ui/aura/window.h" | 5 #include "ui/aura/window.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "ui/aura/client/aura_constants.h" |
| 21 #include "ui/aura/client/capture_client.h" | 22 #include "ui/aura/client/capture_client.h" |
| 22 #include "ui/aura/client/cursor_client.h" | 23 #include "ui/aura/client/cursor_client.h" |
| 23 #include "ui/aura/client/event_client.h" | 24 #include "ui/aura/client/event_client.h" |
| 24 #include "ui/aura/client/focus_client.h" | 25 #include "ui/aura/client/focus_client.h" |
| 25 #include "ui/aura/client/screen_position_client.h" | 26 #include "ui/aura/client/screen_position_client.h" |
| 26 #include "ui/aura/client/visibility_client.h" | 27 #include "ui/aura/client/visibility_client.h" |
| 27 #include "ui/aura/client/window_stacking_client.h" | 28 #include "ui/aura/client/window_stacking_client.h" |
| 28 #include "ui/aura/env.h" | 29 #include "ui/aura/env.h" |
| 29 #include "ui/aura/layout_manager.h" | 30 #include "ui/aura/layout_manager.h" |
| 30 #include "ui/aura/window_delegate.h" | 31 #include "ui/aura/window_delegate.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 layer()->SetFillsBoundsOpaquely(!transparent_); | 152 layer()->SetFillsBoundsOpaquely(!transparent_); |
| 152 Env::GetInstance()->NotifyWindowInitialized(this); | 153 Env::GetInstance()->NotifyWindowInitialized(this); |
| 153 } | 154 } |
| 154 | 155 |
| 155 void Window::SetType(ui::wm::WindowType type) { | 156 void Window::SetType(ui::wm::WindowType type) { |
| 156 // Cannot change type after the window is initialized. | 157 // Cannot change type after the window is initialized. |
| 157 DCHECK(!layer()); | 158 DCHECK(!layer()); |
| 158 type_ = type; | 159 type_ = type; |
| 159 } | 160 } |
| 160 | 161 |
| 162 const std::string& Window::GetName() const { |
| 163 std::string* name = GetProperty(client::kNameKey); |
| 164 return name ? *name : base::EmptyString(); |
| 165 } |
| 166 |
| 161 void Window::SetName(const std::string& name) { | 167 void Window::SetName(const std::string& name) { |
| 162 name_ = name; | 168 if (name == GetName()) |
| 169 return; |
| 170 SetProperty(client::kNameKey, new std::string(name)); |
| 163 if (layer()) | 171 if (layer()) |
| 164 UpdateLayerName(); | 172 UpdateLayerName(); |
| 165 } | 173 } |
| 166 | 174 |
| 175 const base::string16& Window::GetTitle() const { |
| 176 base::string16* title = GetProperty(client::kTitleKey); |
| 177 return title ? *title : base::EmptyString16(); |
| 178 } |
| 179 |
| 167 void Window::SetTitle(const base::string16& title) { | 180 void Window::SetTitle(const base::string16& title) { |
| 168 if (title == title_) | 181 if (title == GetTitle()) |
| 169 return; | 182 return; |
| 170 title_ = title; | 183 SetProperty(client::kTitleKey, new base::string16(title)); |
| 171 for (WindowObserver& observer : observers_) | 184 for (WindowObserver& observer : observers_) |
| 172 observer.OnWindowTitleChanged(this); | 185 observer.OnWindowTitleChanged(this); |
| 173 } | 186 } |
| 174 | 187 |
| 175 void Window::SetTransparent(bool transparent) { | 188 void Window::SetTransparent(bool transparent) { |
| 176 transparent_ = transparent; | 189 transparent_ = transparent; |
| 177 if (layer()) | 190 if (layer()) |
| 178 layer()->SetFillsBoundsOpaquely(!transparent_); | 191 layer()->SetFillsBoundsOpaquely(!transparent_); |
| 179 } | 192 } |
| 180 | 193 |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 } | 615 } |
| 603 | 616 |
| 604 void Window::OnDeviceScaleFactorChanged(float device_scale_factor) { | 617 void Window::OnDeviceScaleFactorChanged(float device_scale_factor) { |
| 605 port_->OnDeviceScaleFactorChanged(device_scale_factor); | 618 port_->OnDeviceScaleFactorChanged(device_scale_factor); |
| 606 } | 619 } |
| 607 | 620 |
| 608 #if !defined(NDEBUG) | 621 #if !defined(NDEBUG) |
| 609 std::string Window::GetDebugInfo() const { | 622 std::string Window::GetDebugInfo() const { |
| 610 return base::StringPrintf( | 623 return base::StringPrintf( |
| 611 "%s<%d> bounds(%d, %d, %d, %d) %s %s opacity=%.1f", | 624 "%s<%d> bounds(%d, %d, %d, %d) %s %s opacity=%.1f", |
| 612 name().empty() ? "Unknown" : name().c_str(), id(), | 625 GetName().empty() ? "Unknown" : GetName().c_str(), id(), bounds().x(), |
| 613 bounds().x(), bounds().y(), bounds().width(), bounds().height(), | 626 bounds().y(), bounds().width(), bounds().height(), |
| 614 visible_ ? "WindowVisible" : "WindowHidden", | 627 visible_ ? "WindowVisible" : "WindowHidden", |
| 615 layer() ? | 628 layer() |
| 616 (layer()->GetTargetVisibility() ? "LayerVisible" : "LayerHidden") : | 629 ? (layer()->GetTargetVisibility() ? "LayerVisible" : "LayerHidden") |
| 617 "NoLayer", | 630 : "NoLayer", |
| 618 layer() ? layer()->opacity() : 1.0f); | 631 layer() ? layer()->opacity() : 1.0f); |
| 619 } | 632 } |
| 620 | 633 |
| 621 void Window::PrintWindowHierarchy(int depth) const { | 634 void Window::PrintWindowHierarchy(int depth) const { |
| 622 VLOG(0) << base::StringPrintf( | 635 VLOG(0) << base::StringPrintf( |
| 623 "%*s%s", depth * 2, "", GetDebugInfo().c_str()); | 636 "%*s%s", depth * 2, "", GetDebugInfo().c_str()); |
| 624 for (Windows::const_iterator it = children_.begin(); | 637 for (Windows::const_iterator it = children_.begin(); |
| 625 it != children_.end(); ++it) { | 638 it != children_.end(); ++it) { |
| 626 Window* child = *it; | 639 Window* child = *it; |
| 627 child->PrintWindowHierarchy(depth + 1); | 640 child->PrintWindowHierarchy(depth + 1); |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 void Window::ConvertEventToTarget(ui::EventTarget* target, | 1104 void Window::ConvertEventToTarget(ui::EventTarget* target, |
| 1092 ui::LocatedEvent* event) { | 1105 ui::LocatedEvent* event) { |
| 1093 event->ConvertLocationToTarget(this, | 1106 event->ConvertLocationToTarget(this, |
| 1094 static_cast<Window*>(target)); | 1107 static_cast<Window*>(target)); |
| 1095 } | 1108 } |
| 1096 | 1109 |
| 1097 void Window::UpdateLayerName() { | 1110 void Window::UpdateLayerName() { |
| 1098 #if !defined(NDEBUG) | 1111 #if !defined(NDEBUG) |
| 1099 DCHECK(layer()); | 1112 DCHECK(layer()); |
| 1100 | 1113 |
| 1101 std::string layer_name(name_); | 1114 std::string layer_name(GetName()); |
| 1102 if (layer_name.empty()) | 1115 if (layer_name.empty()) |
| 1103 layer_name = "Unnamed Window"; | 1116 layer_name = "Unnamed Window"; |
| 1104 | 1117 |
| 1105 if (id_ != -1) | 1118 if (id_ != -1) |
| 1106 layer_name += " " + base::IntToString(id_); | 1119 layer_name += " " + base::IntToString(id_); |
| 1107 | 1120 |
| 1108 layer()->set_name(layer_name); | 1121 layer()->set_name(layer_name); |
| 1109 #endif | 1122 #endif |
| 1110 } | 1123 } |
| 1111 | 1124 |
| 1112 } // namespace aura | 1125 } // namespace aura |
| OLD | NEW |