OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 STLDeleteElements(&transient_children); | 71 STLDeleteElements(&transient_children); |
72 DCHECK(transient_children_.empty()); | 72 DCHECK(transient_children_.empty()); |
73 | 73 |
74 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroyed(this)); | 74 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroyed(this)); |
75 } | 75 } |
76 | 76 |
77 void Window::Init(ui::Layer::LayerType layer_type) { | 77 void Window::Init(ui::Layer::LayerType layer_type) { |
78 layer_.reset(new ui::Layer(layer_type)); | 78 layer_.reset(new ui::Layer(layer_type)); |
79 layer_->SetVisible(false); | 79 layer_->SetVisible(false); |
80 layer_->set_delegate(this); | 80 layer_->set_delegate(this); |
81 | 81 UpdateLayerName(name_); |
82 #if !defined(NDEBUG) | |
83 std::string layer_name(name_); | |
84 if (layer_name.empty()) | |
85 layer_name.append("Unnamed Window"); | |
86 | |
87 if (id_ != -1) { | |
88 char id_buf[10]; | |
89 base::snprintf(id_buf, sizeof(id_buf), " %d", id_); | |
90 layer_name.append(id_buf); | |
91 } | |
92 layer_->set_name(layer_name); | |
93 #endif | |
94 | 82 |
95 Desktop::GetInstance()->WindowInitialized(this); | 83 Desktop::GetInstance()->WindowInitialized(this); |
96 } | 84 } |
97 | 85 |
98 void Window::SetType(WindowType type) { | 86 void Window::SetType(WindowType type) { |
99 // Cannot change type after the window is initialized. | 87 // Cannot change type after the window is initialized. |
100 DCHECK(!layer()); | 88 DCHECK(!layer()); |
101 type_ = type; | 89 type_ = type; |
102 } | 90 } |
103 | 91 |
| 92 void Window::SetName(const std::string& name) { |
| 93 name_ = name; |
| 94 |
| 95 if (layer()) |
| 96 UpdateLayerName(name_); |
| 97 } |
| 98 |
104 void Window::Show() { | 99 void Window::Show() { |
105 SetVisible(true); | 100 SetVisible(true); |
106 } | 101 } |
107 | 102 |
108 void Window::Hide() { | 103 void Window::Hide() { |
109 SetVisible(false); | 104 SetVisible(false); |
110 ReleaseCapture(); | 105 ReleaseCapture(); |
111 if (Desktop::GetInstance()->active_window() == this || | 106 if (Desktop::GetInstance()->active_window() == this || |
112 !Desktop::GetInstance()->active_window()) { | 107 !Desktop::GetInstance()->active_window()) { |
113 Desktop::GetInstance()->ActivateTopmostWindow(); | 108 Desktop::GetInstance()->ActivateTopmostWindow(); |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 | 531 |
537 void Window::OnStackingChanged() { | 532 void Window::OnStackingChanged() { |
538 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowStackingChanged(this)); | 533 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowStackingChanged(this)); |
539 } | 534 } |
540 | 535 |
541 void Window::OnPaintLayer(gfx::Canvas* canvas) { | 536 void Window::OnPaintLayer(gfx::Canvas* canvas) { |
542 if (delegate_) | 537 if (delegate_) |
543 delegate_->OnPaint(canvas); | 538 delegate_->OnPaint(canvas); |
544 } | 539 } |
545 | 540 |
| 541 void Window::UpdateLayerName(const std::string& name) { |
| 542 #if !defined(NDEBUG) |
| 543 DCHECK(layer()); |
| 544 |
| 545 std::string layer_name(name_); |
| 546 if (layer_name.empty()) |
| 547 layer_name.append("Unnamed Window"); |
| 548 |
| 549 if (id_ != -1) { |
| 550 char id_buf[10]; |
| 551 base::snprintf(id_buf, sizeof(id_buf), " %d", id_); |
| 552 layer_name.append(id_buf); |
| 553 } |
| 554 layer()->set_name(layer_name); |
| 555 #endif |
| 556 } |
| 557 |
546 } // namespace aura | 558 } // namespace aura |
OLD | NEW |