Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 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 | |
| 5 #include "chrome_frame/infobars/manager.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/scoped_ptr.h" | |
| 9 | |
| 10 #include "chrome_frame/infobars/internal/host_window.h" | |
| 11 #include "chrome_frame/infobars/internal/infobar_window.h" | |
| 12 | |
| 13 // Connect InfobarWindow to HostWindowManager, and expose the result as an | |
| 14 // InfobarManager | |
| 15 class InfobarManagerImpl | |
| 16 : public InfobarManager, | |
| 17 public InfobarWindow::InfobarHost, | |
| 18 public HostWindowManager::Delegate { | |
| 19 public: | |
| 20 explicit InfobarManagerImpl(HostWindowManager *manager) : manager_(manager) { | |
|
tommi (sloooow) - chröme
2010/11/24 16:08:24
...Manager* manager
erikwright (departed)
2010/12/01 20:05:52
Done.
| |
| 21 for (int index = 0; index < END_OF_INFOBAR_TYPE; ++index) { | |
| 22 infobars_[index].reset( | |
| 23 new InfobarWindow(static_cast<InfobarType>(index), this)); | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 // Implementation of InfobarManager | |
| 28 virtual bool Show(InfobarContent *content, InfobarType type) { | |
|
grt (UTC plus 2)
2010/11/25 18:00:13
InfobarContent*
erikwright (departed)
2010/12/01 20:05:52
Done.
| |
| 29 DCHECK(type >= FIRST_INFOBAR_TYPE && type < END_OF_INFOBAR_TYPE); | |
| 30 | |
| 31 return infobars_[type]->Show(content); | |
| 32 } | |
| 33 | |
| 34 void Hide(InfobarType type) { | |
| 35 DCHECK(type >= FIRST_INFOBAR_TYPE && type < END_OF_INFOBAR_TYPE); | |
| 36 infobars_[type]->Hide(); | |
| 37 } | |
| 38 | |
| 39 void HideAll() { | |
| 40 for (int index = 0; index < END_OF_INFOBAR_TYPE; ++index) | |
| 41 Hide(static_cast<InfobarType>(index)); | |
| 42 } | |
| 43 | |
| 44 // Implementation of HostWindowManager::Delegate | |
| 45 virtual void AdjustDisplacedWindowDimensions(RECT* rect) { | |
| 46 for (int index = 0; index < END_OF_INFOBAR_TYPE; ++index) { | |
| 47 if (infobars_[index] != NULL) | |
| 48 infobars_[index]->ReserveSpace(rect); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 // Implementation of InfobarWindow::InfobarHost | |
| 53 virtual HWND GetContainerWindow() { | |
| 54 return *manager_; | |
| 55 } | |
| 56 virtual bool UpdateLayout() { | |
| 57 return manager_->UpdateLayout(); | |
| 58 } | |
| 59 | |
| 60 private: | |
| 61 // Not owned by this instance. | |
| 62 HostWindowManager *manager_; | |
|
grt (UTC plus 2)
2010/11/25 18:00:13
HostWindowManager*
erikwright (departed)
2010/12/01 20:05:52
Done.
| |
| 63 // Infobar windows. | |
| 64 scoped_ptr<InfobarWindow> infobars_[END_OF_INFOBAR_TYPE]; | |
| 65 DISALLOW_COPY_AND_ASSIGN(InfobarManagerImpl); | |
| 66 }; | |
| 67 | |
| 68 InfobarManager* InfobarManager::Get(HWND tab_window) { | |
| 69 HostWindowManager::Delegate* delegate = | |
| 70 HostWindowManager::GetDelegateForHostHwnd(tab_window); | |
| 71 | |
| 72 if (delegate != NULL) | |
| 73 return static_cast<InfobarManagerImpl*>(delegate); | |
| 74 | |
| 75 scoped_ptr<HostWindowManager> host_manager(new HostWindowManager()); | |
| 76 | |
| 77 // transferred to new_host_manager in Initialize | |
| 78 InfobarManagerImpl* infobar_manager = new InfobarManagerImpl( | |
| 79 host_manager.get()); | |
| 80 | |
| 81 if (host_manager->Initialize(tab_window, infobar_manager)) { | |
| 82 host_manager.release(); // takes ownership of itself | |
| 83 return infobar_manager; | |
| 84 } | |
| 85 | |
| 86 return NULL; | |
| 87 } | |
| OLD | NEW |