Add GetWindows helper that returns a vector
This commit is contained in:
parent
0883a9f966
commit
da5d7d72b0
5 changed files with 11 additions and 21 deletions
|
@ -16,9 +16,7 @@ namespace atom {
|
||||||
|
|
||||||
void Browser::Focus() {
|
void Browser::Focus() {
|
||||||
// Focus on the first visible window.
|
// Focus on the first visible window.
|
||||||
WindowList* list = WindowList::GetInstance();
|
for (const auto& window : WindowList::GetWindows()) {
|
||||||
for (WindowList::iterator iter = list->begin(); iter != list->end(); ++iter) {
|
|
||||||
NativeWindow* window = *iter;
|
|
||||||
if (window->IsVisible()) {
|
if (window->IsVisible()) {
|
||||||
window->Focus(true);
|
window->Focus(true);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -204,9 +204,8 @@ std::string Browser::DockGetBadgeText() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browser::DockHide() {
|
void Browser::DockHide() {
|
||||||
WindowList* list = WindowList::GetInstance();
|
for (const auto& window : WindowList::GetWindows())
|
||||||
for (WindowList::iterator it = list->begin(); it != list->end(); ++it)
|
[window->GetNativeWindow() setCanHide:NO];
|
||||||
[(*it)->GetNativeWindow() setCanHide:NO];
|
|
||||||
|
|
||||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||||
TransformProcessType(&psn, kProcessTransformToUIElementApplication);
|
TransformProcessType(&psn, kProcessTransformToUIElementApplication);
|
||||||
|
|
|
@ -104,8 +104,7 @@ NativeWindow::~NativeWindow() {
|
||||||
// static
|
// static
|
||||||
NativeWindow* NativeWindow::FromWebContents(
|
NativeWindow* NativeWindow::FromWebContents(
|
||||||
content::WebContents* web_contents) {
|
content::WebContents* web_contents) {
|
||||||
WindowList& window_list = *WindowList::GetInstance();
|
for (const auto& window : WindowList::GetWindows()) {
|
||||||
for (NativeWindow* window : window_list) {
|
|
||||||
if (window->web_contents() == web_contents)
|
if (window->web_contents() == web_contents)
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,11 @@ WindowList* WindowList::GetInstance() {
|
||||||
return instance_;
|
return instance_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
WindowList::WindowVector WindowList::GetWindows() {
|
||||||
|
return GetInstance()->windows_;
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void WindowList::AddWindow(NativeWindow* window) {
|
void WindowList::AddWindow(NativeWindow* window) {
|
||||||
DCHECK(window);
|
DCHECK(window);
|
||||||
|
|
|
@ -19,24 +19,13 @@ class WindowListObserver;
|
||||||
class WindowList {
|
class WindowList {
|
||||||
public:
|
public:
|
||||||
typedef std::vector<NativeWindow*> WindowVector;
|
typedef std::vector<NativeWindow*> WindowVector;
|
||||||
typedef WindowVector::iterator iterator;
|
|
||||||
typedef WindowVector::const_iterator const_iterator;
|
|
||||||
|
|
||||||
// Windows are added to the list before they have constructed windows,
|
|
||||||
// so the |window()| member function may return NULL.
|
|
||||||
const_iterator begin() const { return windows_.begin(); }
|
|
||||||
const_iterator end() const { return windows_.end(); }
|
|
||||||
|
|
||||||
iterator begin() { return windows_.begin(); }
|
|
||||||
iterator end() { return windows_.end(); }
|
|
||||||
|
|
||||||
bool empty() const { return windows_.empty(); }
|
bool empty() const { return windows_.empty(); }
|
||||||
size_t size() const { return windows_.size(); }
|
|
||||||
|
|
||||||
NativeWindow* get(size_t index) const { return windows_[index]; }
|
|
||||||
|
|
||||||
static WindowList* GetInstance();
|
static WindowList* GetInstance();
|
||||||
|
|
||||||
|
static WindowVector GetWindows();
|
||||||
|
|
||||||
// Adds or removes |window| from the list it is associated with.
|
// Adds or removes |window| from the list it is associated with.
|
||||||
static void AddWindow(NativeWindow* window);
|
static void AddWindow(NativeWindow* window);
|
||||||
static void RemoveWindow(NativeWindow* window);
|
static void RemoveWindow(NativeWindow* window);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue