| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/mus/public/cpp/window.h" | 5 #include "components/mus/public/cpp/window.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 if (it != children->end()) { | 81 if (it != children->end()) { |
| 82 children->erase(it); | 82 children->erase(it); |
| 83 WindowPrivate(child).ClearParent(); | 83 WindowPrivate(child).ClearParent(); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 class ScopedOrderChangedNotifier { | 87 class ScopedOrderChangedNotifier { |
| 88 public: | 88 public: |
| 89 ScopedOrderChangedNotifier(Window* window, | 89 ScopedOrderChangedNotifier(Window* window, |
| 90 Window* relative_window, | 90 Window* relative_window, |
| 91 mojo::OrderDirection direction) | 91 mojom::OrderDirection direction) |
| 92 : window_(window), | 92 : window_(window), |
| 93 relative_window_(relative_window), | 93 relative_window_(relative_window), |
| 94 direction_(direction) { | 94 direction_(direction) { |
| 95 FOR_EACH_OBSERVER( | 95 FOR_EACH_OBSERVER( |
| 96 WindowObserver, *WindowPrivate(window_).observers(), | 96 WindowObserver, *WindowPrivate(window_).observers(), |
| 97 OnWindowReordering(window_, relative_window_, direction_)); | 97 OnWindowReordering(window_, relative_window_, direction_)); |
| 98 } | 98 } |
| 99 ~ScopedOrderChangedNotifier() { | 99 ~ScopedOrderChangedNotifier() { |
| 100 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window_).observers(), | 100 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window_).observers(), |
| 101 OnWindowReordered(window_, relative_window_, direction_)); | 101 OnWindowReordered(window_, relative_window_, direction_)); |
| 102 } | 102 } |
| 103 | 103 |
| 104 private: | 104 private: |
| 105 Window* window_; | 105 Window* window_; |
| 106 Window* relative_window_; | 106 Window* relative_window_; |
| 107 mojo::OrderDirection direction_; | 107 mojom::OrderDirection direction_; |
| 108 | 108 |
| 109 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedOrderChangedNotifier); | 109 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedOrderChangedNotifier); |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 // Returns true if the order actually changed. | 112 // Returns true if the order actually changed. |
| 113 bool ReorderImpl(Window::Children* children, | 113 bool ReorderImpl(Window::Children* children, |
| 114 Window* window, | 114 Window* window, |
| 115 Window* relative, | 115 Window* relative, |
| 116 mojo::OrderDirection direction) { | 116 mojom::OrderDirection direction) { |
| 117 DCHECK(relative); | 117 DCHECK(relative); |
| 118 DCHECK_NE(window, relative); | 118 DCHECK_NE(window, relative); |
| 119 DCHECK_EQ(window->parent(), relative->parent()); | 119 DCHECK_EQ(window->parent(), relative->parent()); |
| 120 | 120 |
| 121 const size_t child_i = | 121 const size_t child_i = |
| 122 std::find(children->begin(), children->end(), window) - children->begin(); | 122 std::find(children->begin(), children->end(), window) - children->begin(); |
| 123 const size_t target_i = | 123 const size_t target_i = |
| 124 std::find(children->begin(), children->end(), relative) - | 124 std::find(children->begin(), children->end(), relative) - |
| 125 children->begin(); | 125 children->begin(); |
| 126 if ((direction == mojo::ORDER_DIRECTION_ABOVE && child_i == target_i + 1) || | 126 if ((direction == mojom::ORDER_DIRECTION_ABOVE && child_i == target_i + 1) || |
| 127 (direction == mojo::ORDER_DIRECTION_BELOW && child_i + 1 == target_i)) { | 127 (direction == mojom::ORDER_DIRECTION_BELOW && child_i + 1 == target_i)) { |
| 128 return false; | 128 return false; |
| 129 } | 129 } |
| 130 | 130 |
| 131 ScopedOrderChangedNotifier notifier(window, relative, direction); | 131 ScopedOrderChangedNotifier notifier(window, relative, direction); |
| 132 | 132 |
| 133 const size_t dest_i = direction == mojo::ORDER_DIRECTION_ABOVE | 133 const size_t dest_i = direction == mojom::ORDER_DIRECTION_ABOVE |
| 134 ? (child_i < target_i ? target_i : target_i + 1) | 134 ? (child_i < target_i ? target_i : target_i + 1) |
| 135 : (child_i < target_i ? target_i - 1 : target_i); | 135 : (child_i < target_i ? target_i - 1 : target_i); |
| 136 children->erase(children->begin() + child_i); | 136 children->erase(children->begin() + child_i); |
| 137 children->insert(children->begin() + dest_i, window); | 137 children->insert(children->begin() + dest_i, window); |
| 138 | 138 |
| 139 return true; | 139 return true; |
| 140 } | 140 } |
| 141 | 141 |
| 142 class ScopedSetBoundsNotifier { | 142 class ScopedSetBoundsNotifier { |
| 143 public: | 143 public: |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 void Window::SetVisible(bool value) { | 226 void Window::SetVisible(bool value) { |
| 227 if (visible_ == value) | 227 if (visible_ == value) |
| 228 return; | 228 return; |
| 229 | 229 |
| 230 if (connection_) | 230 if (connection_) |
| 231 static_cast<WindowTreeClientImpl*>(connection_)->SetVisible(id_, value); | 231 static_cast<WindowTreeClientImpl*>(connection_)->SetVisible(id_, value); |
| 232 LocalSetVisible(value); | 232 LocalSetVisible(value); |
| 233 } | 233 } |
| 234 | 234 |
| 235 scoped_ptr<WindowSurface> Window::RequestSurface() { | 235 scoped_ptr<WindowSurface> Window::RequestSurface() { |
| 236 mojo::SurfacePtr surface; | 236 mojom::SurfacePtr surface; |
| 237 mojo::SurfaceClientPtr client; | 237 mojom::SurfaceClientPtr client; |
| 238 mojo::InterfaceRequest<mojo::SurfaceClient> client_request = | 238 mojo::InterfaceRequest<mojom::SurfaceClient> client_request = |
| 239 GetProxy(&client); | 239 GetProxy(&client); |
| 240 static_cast<WindowTreeClientImpl*>(connection_) | 240 static_cast<WindowTreeClientImpl*>(connection_) |
| 241 ->RequestSurface(id_, GetProxy(&surface), client.Pass()); | 241 ->RequestSurface(id_, GetProxy(&surface), client.Pass()); |
| 242 return make_scoped_ptr( | 242 return make_scoped_ptr( |
| 243 new WindowSurface(surface.PassInterface(), client_request.Pass())); | 243 new WindowSurface(surface.PassInterface(), client_request.Pass())); |
| 244 } | 244 } |
| 245 | 245 |
| 246 void Window::SetSharedProperty(const std::string& name, | 246 void Window::SetSharedProperty(const std::string& name, |
| 247 const std::vector<uint8_t>* value) { | 247 const std::vector<uint8_t>* value) { |
| 248 std::vector<uint8_t> old_value; | 248 std::vector<uint8_t> old_value; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 LocalRemoveChild(child); | 322 LocalRemoveChild(child); |
| 323 if (connection_) { | 323 if (connection_) { |
| 324 static_cast<WindowTreeClientImpl*>(connection_) | 324 static_cast<WindowTreeClientImpl*>(connection_) |
| 325 ->RemoveChild(child->id(), id_); | 325 ->RemoveChild(child->id(), id_); |
| 326 } | 326 } |
| 327 } | 327 } |
| 328 | 328 |
| 329 void Window::MoveToFront() { | 329 void Window::MoveToFront() { |
| 330 if (!parent_ || parent_->children_.back() == this) | 330 if (!parent_ || parent_->children_.back() == this) |
| 331 return; | 331 return; |
| 332 Reorder(parent_->children_.back(), mojo::ORDER_DIRECTION_ABOVE); | 332 Reorder(parent_->children_.back(), mojom::ORDER_DIRECTION_ABOVE); |
| 333 } | 333 } |
| 334 | 334 |
| 335 void Window::MoveToBack() { | 335 void Window::MoveToBack() { |
| 336 if (!parent_ || parent_->children_.front() == this) | 336 if (!parent_ || parent_->children_.front() == this) |
| 337 return; | 337 return; |
| 338 Reorder(parent_->children_.front(), mojo::ORDER_DIRECTION_BELOW); | 338 Reorder(parent_->children_.front(), mojom::ORDER_DIRECTION_BELOW); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void Window::Reorder(Window* relative, mojo::OrderDirection direction) { | 341 void Window::Reorder(Window* relative, mojom::OrderDirection direction) { |
| 342 if (!LocalReorder(relative, direction)) | 342 if (!LocalReorder(relative, direction)) |
| 343 return; | 343 return; |
| 344 if (connection_) { | 344 if (connection_) { |
| 345 static_cast<WindowTreeClientImpl*>(connection_) | 345 static_cast<WindowTreeClientImpl*>(connection_) |
| 346 ->Reorder(id_, relative->id(), direction); | 346 ->Reorder(id_, relative->id(), direction); |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 | 349 |
| 350 bool Window::Contains(Window* child) const { | 350 bool Window::Contains(Window* child) const { |
| 351 if (!child) | 351 if (!child) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 371 Window* window = (*it)->GetChildById(id); | 371 Window* window = (*it)->GetChildById(id); |
| 372 if (window) | 372 if (window) |
| 373 return window; | 373 return window; |
| 374 } | 374 } |
| 375 return NULL; | 375 return NULL; |
| 376 } | 376 } |
| 377 | 377 |
| 378 void Window::SetTextInputState(mojo::TextInputStatePtr state) { | 378 void Window::SetTextInputState(mojo::TextInputStatePtr state) { |
| 379 if (connection_) { | 379 if (connection_) { |
| 380 static_cast<WindowTreeClientImpl*>(connection_) | 380 static_cast<WindowTreeClientImpl*>(connection_) |
| 381 ->SetViewTextInputState(id_, state.Pass()); | 381 ->SetWindowTextInputState(id_, state.Pass()); |
| 382 } | 382 } |
| 383 } | 383 } |
| 384 | 384 |
| 385 void Window::SetImeVisibility(bool visible, mojo::TextInputStatePtr state) { | 385 void Window::SetImeVisibility(bool visible, mojo::TextInputStatePtr state) { |
| 386 // SetImeVisibility() shouldn't be used if the window is not editable. | 386 // SetImeVisibility() shouldn't be used if the window is not editable. |
| 387 DCHECK(state.is_null() || state->type != mojo::TEXT_INPUT_TYPE_NONE); | 387 DCHECK(state.is_null() || state->type != mojo::TEXT_INPUT_TYPE_NONE); |
| 388 if (connection_) { | 388 if (connection_) { |
| 389 static_cast<WindowTreeClientImpl*>(connection_) | 389 static_cast<WindowTreeClientImpl*>(connection_) |
| 390 ->SetImeVisibility(id_, visible, state.Pass()); | 390 ->SetImeVisibility(id_, visible, state.Pass()); |
| 391 } | 391 } |
| 392 } | 392 } |
| 393 | 393 |
| 394 void Window::SetFocus() { | 394 void Window::SetFocus() { |
| 395 if (connection_) | 395 if (connection_) |
| 396 static_cast<WindowTreeClientImpl*>(connection_)->SetFocus(id_); | 396 static_cast<WindowTreeClientImpl*>(connection_)->SetFocus(id_); |
| 397 } | 397 } |
| 398 | 398 |
| 399 bool Window::HasFocus() const { | 399 bool Window::HasFocus() const { |
| 400 return connection_ && connection_->GetFocusedWindow() == this; | 400 return connection_ && connection_->GetFocusedWindow() == this; |
| 401 } | 401 } |
| 402 | 402 |
| 403 void Window::Embed(mojo::ViewTreeClientPtr client) { | 403 void Window::Embed(mus::mojom::WindowTreeClientPtr client) { |
| 404 Embed(client.Pass(), mojo::ViewTree::ACCESS_POLICY_DEFAULT, | 404 Embed(client.Pass(), mus::mojom::WindowTree::ACCESS_POLICY_DEFAULT, |
| 405 base::Bind(&EmptyEmbedCallback)); | 405 base::Bind(&EmptyEmbedCallback)); |
| 406 } | 406 } |
| 407 | 407 |
| 408 void Window::Embed(mojo::ViewTreeClientPtr client, | 408 void Window::Embed(mus::mojom::WindowTreeClientPtr client, |
| 409 uint32_t policy_bitmask, | 409 uint32_t policy_bitmask, |
| 410 const EmbedCallback& callback) { | 410 const EmbedCallback& callback) { |
| 411 if (PrepareForEmbed()) { | 411 if (PrepareForEmbed()) { |
| 412 static_cast<WindowTreeClientImpl*>(connection_) | 412 static_cast<WindowTreeClientImpl*>(connection_) |
| 413 ->Embed(id_, client.Pass(), policy_bitmask, callback); | 413 ->Embed(id_, client.Pass(), policy_bitmask, callback); |
| 414 } else { | 414 } else { |
| 415 callback.Run(false, 0); | 415 callback.Run(false, 0); |
| 416 } | 416 } |
| 417 } | 417 } |
| 418 | 418 |
| 419 //////////////////////////////////////////////////////////////////////////////// | 419 //////////////////////////////////////////////////////////////////////////////// |
| 420 // Window, protected: | 420 // Window, protected: |
| 421 | 421 |
| 422 namespace { | 422 namespace { |
| 423 | 423 |
| 424 mojo::ViewportMetricsPtr CreateEmptyViewportMetrics() { | 424 mojom::ViewportMetricsPtr CreateEmptyViewportMetrics() { |
| 425 mojo::ViewportMetricsPtr metrics = mojo::ViewportMetrics::New(); | 425 mojom::ViewportMetricsPtr metrics = mojom::ViewportMetrics::New(); |
| 426 metrics->size_in_pixels = mojo::Size::New(); | 426 metrics->size_in_pixels = mojo::Size::New(); |
| 427 // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it | 427 // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it |
| 428 // once that's fixed. | 428 // once that's fixed. |
| 429 return metrics.Pass(); | 429 return metrics.Pass(); |
| 430 } | 430 } |
| 431 | 431 |
| 432 } // namespace | 432 } // namespace |
| 433 | 433 |
| 434 Window::Window() | 434 Window::Window() |
| 435 : connection_(NULL), | 435 : connection_(NULL), |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 children_.push_back(child); | 520 children_.push_back(child); |
| 521 child->parent_ = this; | 521 child->parent_ = this; |
| 522 } | 522 } |
| 523 | 523 |
| 524 void Window::LocalRemoveChild(Window* child) { | 524 void Window::LocalRemoveChild(Window* child) { |
| 525 DCHECK_EQ(this, child->parent()); | 525 DCHECK_EQ(this, child->parent()); |
| 526 ScopedTreeNotifier notifier(child, this, NULL); | 526 ScopedTreeNotifier notifier(child, this, NULL); |
| 527 RemoveChildImpl(child, &children_); | 527 RemoveChildImpl(child, &children_); |
| 528 } | 528 } |
| 529 | 529 |
| 530 bool Window::LocalReorder(Window* relative, mojo::OrderDirection direction) { | 530 bool Window::LocalReorder(Window* relative, mojom::OrderDirection direction) { |
| 531 return ReorderImpl(&parent_->children_, this, relative, direction); | 531 return ReorderImpl(&parent_->children_, this, relative, direction); |
| 532 } | 532 } |
| 533 | 533 |
| 534 void Window::LocalSetBounds(const mojo::Rect& old_bounds, | 534 void Window::LocalSetBounds(const mojo::Rect& old_bounds, |
| 535 const mojo::Rect& new_bounds) { | 535 const mojo::Rect& new_bounds) { |
| 536 DCHECK(old_bounds.x == bounds_.x); | 536 DCHECK(old_bounds.x == bounds_.x); |
| 537 DCHECK(old_bounds.y == bounds_.y); | 537 DCHECK(old_bounds.y == bounds_.y); |
| 538 DCHECK(old_bounds.width == bounds_.width); | 538 DCHECK(old_bounds.width == bounds_.width); |
| 539 DCHECK(old_bounds.height == bounds_.height); | 539 DCHECK(old_bounds.height == bounds_.height); |
| 540 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds); | 540 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds); |
| 541 if (bounds_.width != new_bounds.width || | 541 if (bounds_.width != new_bounds.width || |
| 542 bounds_.height != new_bounds.height) { | 542 bounds_.height != new_bounds.height) { |
| 543 client_area_.x = 0; | 543 client_area_.x = 0; |
| 544 client_area_.y = 0; | 544 client_area_.y = 0; |
| 545 client_area_.width = new_bounds.width; | 545 client_area_.width = new_bounds.width; |
| 546 client_area_.height = new_bounds.height; | 546 client_area_.height = new_bounds.height; |
| 547 } | 547 } |
| 548 bounds_ = new_bounds; | 548 bounds_ = new_bounds; |
| 549 } | 549 } |
| 550 | 550 |
| 551 void Window::LocalSetClientArea(const mojo::Rect& new_client_area) { | 551 void Window::LocalSetClientArea(const mojo::Rect& new_client_area) { |
| 552 const mojo::Rect old_client_area = client_area_; | 552 const mojo::Rect old_client_area = client_area_; |
| 553 client_area_ = new_client_area; | 553 client_area_ = new_client_area; |
| 554 FOR_EACH_OBSERVER(WindowObserver, observers_, | 554 FOR_EACH_OBSERVER(WindowObserver, observers_, |
| 555 OnWindowClientAreaChanged(this, old_client_area)); | 555 OnWindowClientAreaChanged(this, old_client_area)); |
| 556 } | 556 } |
| 557 | 557 |
| 558 void Window::LocalSetViewportMetrics(const mojo::ViewportMetrics& old_metrics, | 558 void Window::LocalSetViewportMetrics( |
| 559 const mojo::ViewportMetrics& new_metrics) { | 559 const mojom::ViewportMetrics& old_metrics, |
| 560 const mojom::ViewportMetrics& new_metrics) { |
| 560 // TODO(eseidel): We could check old_metrics against viewport_metrics_. | 561 // TODO(eseidel): We could check old_metrics against viewport_metrics_. |
| 561 viewport_metrics_ = new_metrics.Clone(); | 562 viewport_metrics_ = new_metrics.Clone(); |
| 562 FOR_EACH_OBSERVER( | 563 FOR_EACH_OBSERVER( |
| 563 WindowObserver, observers_, | 564 WindowObserver, observers_, |
| 564 OnWindowViewportMetricsChanged(this, old_metrics, new_metrics)); | 565 OnWindowViewportMetricsChanged(this, old_metrics, new_metrics)); |
| 565 } | 566 } |
| 566 | 567 |
| 567 void Window::LocalSetDrawn(bool value) { | 568 void Window::LocalSetDrawn(bool value) { |
| 568 if (drawn_ == value) | 569 if (drawn_ == value) |
| 569 return; | 570 return; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 !static_cast<WindowTreeClientImpl*>(connection_)->is_embed_root()) { | 644 !static_cast<WindowTreeClientImpl*>(connection_)->is_embed_root()) { |
| 644 return false; | 645 return false; |
| 645 } | 646 } |
| 646 | 647 |
| 647 while (!children_.empty()) | 648 while (!children_.empty()) |
| 648 RemoveChild(children_[0]); | 649 RemoveChild(children_[0]); |
| 649 return true; | 650 return true; |
| 650 } | 651 } |
| 651 | 652 |
| 652 } // namespace mus | 653 } // namespace mus |
| OLD | NEW |