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