| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "mash/browser/browser.h" | 5 #include "mash/browser/browser.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 Tab* tab = new Tab(std::move(view), this); | 198 Tab* tab = new Tab(std::move(view), this); |
| 199 // We won't have a WindowTree until we're added to a view hierarchy. | 199 // We won't have a WindowTree until we're added to a view hierarchy. |
| 200 if (container_) { | 200 if (container_) { |
| 201 ui::Window* window = container_->window_tree()->NewWindow(); | 201 ui::Window* window = container_->window_tree()->NewWindow(); |
| 202 container_->AddChild(window); | 202 container_->AddChild(window); |
| 203 tab->SetWindow(window); | 203 tab->SetWindow(window); |
| 204 } | 204 } |
| 205 AddObserver(tab); | 205 AddObserver(tab); |
| 206 tabs_.push_back(tab); | 206 tabs_.push_back(tab); |
| 207 tab_container_->AddChildView(tab); | 207 tab_container_->AddChildView(tab); |
| 208 FOR_EACH_OBSERVER(TabStripObserver, observers_, OnTabAdded(tab)); | 208 for (auto& observer : observers_) |
| 209 observer.OnTabAdded(tab); |
| 209 SelectTab(tab); | 210 SelectTab(tab); |
| 210 } | 211 } |
| 211 | 212 |
| 212 void CloseTabForView(navigation::View* view) { | 213 void CloseTabForView(navigation::View* view) { |
| 213 for (auto it = tabs_.begin(); it != tabs_.end(); ++it) { | 214 for (auto it = tabs_.begin(); it != tabs_.end(); ++it) { |
| 214 Tab* tab = *it; | 215 Tab* tab = *it; |
| 215 if (tab->view() == view) { | 216 if (tab->view() == view) { |
| 216 CloseTab(tab); | 217 CloseTab(tab); |
| 217 break; | 218 break; |
| 218 } | 219 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 229 RemoveObserver(tab); | 230 RemoveObserver(tab); |
| 230 tab_container_->RemoveChildView(tab); | 231 tab_container_->RemoveChildView(tab); |
| 231 if (tab->selected()) { | 232 if (tab->selected()) { |
| 232 int next_selected_index = selected_index_; | 233 int next_selected_index = selected_index_; |
| 233 if (selected_index_ == static_cast<int>(tabs_.size())) | 234 if (selected_index_ == static_cast<int>(tabs_.size())) |
| 234 --next_selected_index; | 235 --next_selected_index; |
| 235 if (next_selected_index >= 0) | 236 if (next_selected_index >= 0) |
| 236 SelectTab(tabs_[next_selected_index]); | 237 SelectTab(tabs_[next_selected_index]); |
| 237 } | 238 } |
| 238 Layout(); | 239 Layout(); |
| 239 FOR_EACH_OBSERVER(TabStripObserver, observers_, OnTabRemoved(tab)); | 240 for (auto& observer : observers_) |
| 241 observer.OnTabRemoved(tab); |
| 240 delete tab; | 242 delete tab; |
| 241 } | 243 } |
| 242 | 244 |
| 243 bool empty() const { return tabs_.empty(); } | 245 bool empty() const { return tabs_.empty(); } |
| 244 | 246 |
| 245 void SelectTab(Tab* tab) { | 247 void SelectTab(Tab* tab) { |
| 246 auto it = std::find(tabs_.begin(), tabs_.end(), tab); | 248 auto it = std::find(tabs_.begin(), tabs_.end(), tab); |
| 247 DCHECK(it != tabs_.end()); | 249 DCHECK(it != tabs_.end()); |
| 248 selected_index_ = it - tabs_.begin(); | 250 selected_index_ = it - tabs_.begin(); |
| 249 FOR_EACH_OBSERVER(TabStripObserver, observers_, OnTabSelected(tab)); | 251 for (auto& observer : observers_) |
| 252 observer.OnTabSelected(tab); |
| 250 } | 253 } |
| 251 Tab* selected_tab() { | 254 Tab* selected_tab() { |
| 252 return selected_index_ != -1 ? tabs_[selected_index_] : nullptr; | 255 return selected_index_ != -1 ? tabs_[selected_index_] : nullptr; |
| 253 } | 256 } |
| 254 | 257 |
| 255 void AddObserver(TabStripObserver* observer) { | 258 void AddObserver(TabStripObserver* observer) { |
| 256 observers_.AddObserver(observer); | 259 observers_.AddObserver(observer); |
| 257 } | 260 } |
| 258 void RemoveObserver(TabStripObserver* observer) { | 261 void RemoveObserver(TabStripObserver* observer) { |
| 259 observers_.RemoveObserver(observer); | 262 observers_.RemoveObserver(observer); |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 AddWindow(window); | 898 AddWindow(window); |
| 896 } | 899 } |
| 897 | 900 |
| 898 void Browser::Create(const shell::Identity& remote_identity, | 901 void Browser::Create(const shell::Identity& remote_identity, |
| 899 mojom::LaunchableRequest request) { | 902 mojom::LaunchableRequest request) { |
| 900 bindings_.AddBinding(this, std::move(request)); | 903 bindings_.AddBinding(this, std::move(request)); |
| 901 } | 904 } |
| 902 | 905 |
| 903 } // namespace browser | 906 } // namespace browser |
| 904 } // namespace mash | 907 } // namespace mash |
| OLD | NEW |