Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1479)

Side by Side Diff: ui/aura/window.cc

Issue 944763002: Make Page Visibility API work when the browser window is visible or not Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove the VisibilityNotify event handler Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 else if (layer()) 945 else if (layer())
946 layer()->SetVisible(visible); 946 layer()->SetVisible(visible);
947 visible_ = visible; 947 visible_ = visible;
948 SchedulePaint(); 948 SchedulePaint();
949 if (parent_ && parent_->layout_manager_) 949 if (parent_ && parent_->layout_manager_)
950 parent_->layout_manager_->OnChildWindowVisibilityChanged(this, visible); 950 parent_->layout_manager_->OnChildWindowVisibilityChanged(this, visible);
951 951
952 if (delegate_) 952 if (delegate_)
953 delegate_->OnWindowTargetVisibilityChanged(visible); 953 delegate_->OnWindowTargetVisibilityChanged(visible);
954 954
955 NotifyWindowVisibilityChanged(this, visible); 955 NotifyWindowVisibilityChanged(this, visible, false);
956 } 956 }
957 957
958 #if defined(OS_LINUX)
959 // Trigger the VisibilityChange event.
960 void Window::SetPageVisibility(bool visible) {
961 // The third parameter is used to show content even if the visible parameter
962 // is false, which is needed for a workspace view like Mac Expose.
963 NotifyWindowVisibilityChanged(this, visible, true);
964 }
965 #endif
966
958 void Window::SchedulePaint() { 967 void Window::SchedulePaint() {
959 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); 968 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height()));
960 } 969 }
961 970
962 void Window::Paint(gfx::Canvas* canvas) { 971 void Window::Paint(gfx::Canvas* canvas) {
963 if (delegate_) 972 if (delegate_)
964 delegate_->OnPaint(canvas); 973 delegate_->OnPaint(canvas);
965 PaintLayerlessChildren(canvas); 974 PaintLayerlessChildren(canvas);
966 } 975 }
967 976
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 FOR_EACH_OBSERVER(WindowObserver, observers_, 1284 FOR_EACH_OBSERVER(WindowObserver, observers_,
1276 OnWindowHierarchyChanged(local_params)); 1285 OnWindowHierarchyChanged(local_params));
1277 break; 1286 break;
1278 default: 1287 default:
1279 NOTREACHED(); 1288 NOTREACHED();
1280 break; 1289 break;
1281 } 1290 }
1282 } 1291 }
1283 1292
1284 void Window::NotifyWindowVisibilityChanged(aura::Window* target, 1293 void Window::NotifyWindowVisibilityChanged(aura::Window* target,
1285 bool visible) { 1294 bool visible, bool content_visible) {
1286 if (!NotifyWindowVisibilityChangedDown(target, visible)) { 1295 if (!NotifyWindowVisibilityChangedDown(target, visible, content_visible)) {
1287 return; // |this| has been deleted. 1296 return; // |this| has been deleted.
1288 } 1297 }
1289 NotifyWindowVisibilityChangedUp(target, visible); 1298 NotifyWindowVisibilityChangedUp(target, visible);
1290 } 1299 }
1291 1300
1292 bool Window::NotifyWindowVisibilityChangedAtReceiver(aura::Window* target, 1301 bool Window::NotifyWindowVisibilityChangedAtReceiver(aura::Window* target,
1293 bool visible) { 1302 bool visible,
1303 bool content_visible) {
1294 // |this| may be deleted during a call to OnWindowVisibilityChanged() on one 1304 // |this| may be deleted during a call to OnWindowVisibilityChanged() on one
1295 // of the observers. We create an local observer for that. In that case we 1305 // of the observers. We create an local observer for that. In that case we
1296 // exit without further access to any members. 1306 // exit without further access to any members.
1297 WindowTracker tracker; 1307 WindowTracker tracker;
1298 tracker.Add(this); 1308 tracker.Add(this);
1299 FOR_EACH_OBSERVER(WindowObserver, observers_, 1309 FOR_EACH_OBSERVER(WindowObserver, observers_,
1300 OnWindowVisibilityChanged(target, visible)); 1310 OnWindowVisibilityChanged(target, visible, content_visible));
1301 return tracker.Contains(this); 1311 return tracker.Contains(this);
1302 } 1312 }
1303 1313
1304 bool Window::NotifyWindowVisibilityChangedDown(aura::Window* target, 1314 bool Window::NotifyWindowVisibilityChangedDown(aura::Window* target,
1305 bool visible) { 1315 bool visible,
1306 if (!NotifyWindowVisibilityChangedAtReceiver(target, visible)) 1316 bool content_visible) {
1317 if (!NotifyWindowVisibilityChangedAtReceiver(target, visible,
1318 content_visible))
1307 return false; // |this| was deleted. 1319 return false; // |this| was deleted.
1308 std::set<const Window*> child_already_processed; 1320 std::set<const Window*> child_already_processed;
1309 bool child_destroyed = false; 1321 bool child_destroyed = false;
1310 do { 1322 do {
1311 child_destroyed = false; 1323 child_destroyed = false;
1312 for (Window::Windows::const_iterator it = children_.begin(); 1324 for (Window::Windows::const_iterator it = children_.begin();
1313 it != children_.end(); ++it) { 1325 it != children_.end(); ++it) {
1314 if (!child_already_processed.insert(*it).second) 1326 if (!child_already_processed.insert(*it).second)
1315 continue; 1327 continue;
1316 if (!(*it)->NotifyWindowVisibilityChangedDown(target, visible)) { 1328 if (!(*it)->NotifyWindowVisibilityChangedDown(target, visible,
1329 content_visible)) {
1317 // |*it| was deleted, |it| is invalid and |children_| has changed. 1330 // |*it| was deleted, |it| is invalid and |children_| has changed.
1318 // We exit the current for-loop and enter a new one. 1331 // We exit the current for-loop and enter a new one.
1319 child_destroyed = true; 1332 child_destroyed = true;
1320 break; 1333 break;
1321 } 1334 }
1322 } 1335 }
1323 } while (child_destroyed); 1336 } while (child_destroyed);
1324 return true; 1337 return true;
1325 } 1338 }
1326 1339
1327 void Window::NotifyWindowVisibilityChangedUp(aura::Window* target, 1340 void Window::NotifyWindowVisibilityChangedUp(aura::Window* target,
1328 bool visible) { 1341 bool visible) {
1329 // Start with the parent as we already notified |this| 1342 // Start with the parent as we already notified |this|
1330 // in NotifyWindowVisibilityChangedDown. 1343 // in NotifyWindowVisibilityChangedDown.
1331 for (Window* window = parent(); window; window = window->parent()) { 1344 for (Window* window = parent(); window; window = window->parent()) {
1332 bool ret = window->NotifyWindowVisibilityChangedAtReceiver(target, visible); 1345 bool ret = window->NotifyWindowVisibilityChangedAtReceiver(target, visible,
1346 false);
1333 DCHECK(ret); 1347 DCHECK(ret);
1334 } 1348 }
1335 } 1349 }
1336 1350
1337 void Window::NotifyAncestorWindowTransformed(Window* source) { 1351 void Window::NotifyAncestorWindowTransformed(Window* source) {
1338 FOR_EACH_OBSERVER(WindowObserver, observers_, 1352 FOR_EACH_OBSERVER(WindowObserver, observers_,
1339 OnAncestorWindowTransformed(source, this)); 1353 OnAncestorWindowTransformed(source, this));
1340 for (Window::Windows::const_iterator it = children_.begin(); 1354 for (Window::Windows::const_iterator it = children_.begin();
1341 it != children_.end(); ++it) { 1355 it != children_.end(); ++it) {
1342 (*it)->NotifyAncestorWindowTransformed(source); 1356 (*it)->NotifyAncestorWindowTransformed(source);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 return window; 1478 return window;
1465 if (offset) 1479 if (offset)
1466 *offset += window->bounds().OffsetFromOrigin(); 1480 *offset += window->bounds().OffsetFromOrigin();
1467 } 1481 }
1468 if (offset) 1482 if (offset)
1469 *offset = gfx::Vector2d(); 1483 *offset = gfx::Vector2d();
1470 return NULL; 1484 return NULL;
1471 } 1485 }
1472 1486
1473 } // namespace aura 1487 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698