OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/test_runner/layout_and_paint_async_then.h" | |
6 | |
7 #include "base/callback.h" | |
8 #include "base/trace_event/trace_event.h" | |
9 #include "third_party/WebKit/public/platform/WebLayoutAndPaintAsyncCallback.h" | |
10 #include "third_party/WebKit/public/web/WebPagePopup.h" | |
11 #include "third_party/WebKit/public/web/WebWidget.h" | |
12 | |
13 namespace test_runner { | |
14 | |
15 namespace { | |
16 | |
17 class LayoutAndPaintCallback : public blink::WebLayoutAndPaintAsyncCallback { | |
18 public: | |
19 LayoutAndPaintCallback(const base::Closure& callback) | |
20 : callback_(callback), wait_for_popup_(false) {} | |
21 virtual ~LayoutAndPaintCallback() {} | |
22 | |
23 void set_wait_for_popup(bool wait) { wait_for_popup_ = wait; } | |
24 | |
25 // WebLayoutAndPaintAsyncCallback implementation. | |
26 void didLayoutAndPaint() override; | |
27 | |
28 private: | |
29 base::Closure callback_; | |
30 bool wait_for_popup_; | |
31 }; | |
32 | |
33 void LayoutAndPaintCallback::didLayoutAndPaint() { | |
34 TRACE_EVENT0("shell", "LayoutAndPaintCallback::didLayoutAndPaint"); | |
35 if (wait_for_popup_) { | |
36 wait_for_popup_ = false; | |
37 return; | |
38 } | |
39 | |
40 if (!callback_.is_null()) | |
41 callback_.Run(); | |
42 delete this; | |
43 } | |
44 | |
45 } // namespace | |
46 | |
47 void LayoutAndPaintAsyncThen(blink::WebWidget* web_widget, | |
48 const base::Closure& callback) { | |
49 TRACE_EVENT0("shell", "LayoutAndPaintAsyncThen"); | |
50 | |
51 LayoutAndPaintCallback* layout_and_paint_callback = | |
52 new LayoutAndPaintCallback(callback); | |
53 web_widget->layoutAndPaintAsync(layout_and_paint_callback); | |
54 if (blink::WebPagePopup* popup = web_widget->pagePopup()) { | |
55 layout_and_paint_callback->set_wait_for_popup(true); | |
56 popup->layoutAndPaintAsync(layout_and_paint_callback); | |
57 } | |
58 } | |
59 | |
60 } // namespace test_runner | |
OLD | NEW |