OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. | |
3 * Copyright (C) 2013 Google Inc. All rights reserved. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions | |
7 * are met: | |
8 * 1. Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright | |
11 * notice, this list of conditions and the following disclaimer in the | |
12 * documentation and/or other materials provided with the distribution. | |
13 * | |
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
25 */ | |
26 | |
27 #include "platform/FrameViewBase.h" | |
28 | |
29 #include "platform/wtf/Assertions.h" | |
30 | |
31 namespace blink { | |
32 | |
33 FrameViewBase::FrameViewBase() | |
34 : parent_(nullptr), self_visible_(false), parent_visible_(false) {} | |
35 | |
36 FrameViewBase::~FrameViewBase() {} | |
37 | |
38 DEFINE_TRACE(FrameViewBase) { | |
39 visitor->Trace(parent_); | |
40 } | |
41 | |
42 void FrameViewBase::SetParent(FrameViewBase* frame_view_base) { | |
43 DCHECK(!frame_view_base || !parent_); | |
44 if (!frame_view_base || !frame_view_base->IsVisible()) | |
45 SetParentVisible(false); | |
46 parent_ = frame_view_base; | |
47 if (frame_view_base && frame_view_base->IsVisible()) | |
48 SetParentVisible(true); | |
49 } | |
50 | |
51 FrameViewBase* FrameViewBase::Root() const { | |
52 const FrameViewBase* top = this; | |
53 while (top->Parent()) | |
54 top = top->Parent(); | |
55 if (top->IsFrameView()) | |
56 return const_cast<FrameViewBase*>(static_cast<const FrameViewBase*>(top)); | |
57 return 0; | |
58 } | |
59 | |
60 IntRect FrameViewBase::ConvertFromRootFrame( | |
61 const IntRect& rect_in_root_frame) const { | |
62 if (const FrameViewBase* parent_frame_view_base = Parent()) { | |
63 IntRect parent_rect = | |
64 parent_frame_view_base->ConvertFromRootFrame(rect_in_root_frame); | |
65 return ConvertFromContainingFrameViewBase(parent_rect); | |
66 } | |
67 return rect_in_root_frame; | |
68 } | |
69 | |
70 IntPoint FrameViewBase::ConvertFromRootFrame( | |
71 const IntPoint& point_in_root_frame) const { | |
72 if (const FrameViewBase* parent_frame_view_base = Parent()) { | |
73 IntPoint parent_point = | |
74 parent_frame_view_base->ConvertFromRootFrame(point_in_root_frame); | |
75 return ConvertFromContainingFrameViewBase(parent_point); | |
76 } | |
77 return point_in_root_frame; | |
78 } | |
79 | |
80 FloatPoint FrameViewBase::ConvertFromRootFrame( | |
81 const FloatPoint& point_in_root_frame) const { | |
82 // FrameViewBase / windows are required to be IntPoint aligned, but we may | |
83 // need to convert FloatPoint values within them (eg. for event co-ordinates). | |
84 IntPoint floored_point = FlooredIntPoint(point_in_root_frame); | |
85 FloatPoint parent_point = ConvertFromRootFrame(floored_point); | |
86 FloatSize window_fraction = point_in_root_frame - floored_point; | |
87 // Use linear interpolation handle any fractional value (eg. for iframes | |
88 // subject to a transform beyond just a simple translation). | |
89 // FIXME: Add FloatPoint variants of all co-ordinate space conversion APIs. | |
90 if (!window_fraction.IsEmpty()) { | |
91 const int kFactor = 1000; | |
92 IntPoint parent_line_end = ConvertFromRootFrame( | |
93 floored_point + RoundedIntSize(window_fraction.ScaledBy(kFactor))); | |
94 FloatSize parent_fraction = | |
95 (parent_line_end - parent_point).ScaledBy(1.0f / kFactor); | |
96 parent_point.Move(parent_fraction); | |
97 } | |
98 return parent_point; | |
99 } | |
100 | |
101 } // namespace blink | |
OLD | NEW |