• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The Chromium Embedded Framework Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be found
3 // in the LICENSE file.
4 
5 #include "libcef/browser/views/scroll_view_impl.h"
6 
7 // static
CreateScrollView(CefRefPtr<CefViewDelegate> delegate)8 CefRefPtr<CefScrollView> CefScrollView::CreateScrollView(
9     CefRefPtr<CefViewDelegate> delegate) {
10   return CefScrollViewImpl::Create(delegate);
11 }
12 
13 // static
Create(CefRefPtr<CefViewDelegate> delegate)14 CefRefPtr<CefScrollViewImpl> CefScrollViewImpl::Create(
15     CefRefPtr<CefViewDelegate> delegate) {
16   CEF_REQUIRE_UIT_RETURN(nullptr);
17   CefRefPtr<CefScrollViewImpl> view = new CefScrollViewImpl(delegate);
18   view->Initialize();
19   return view;
20 }
21 
SetContentView(CefRefPtr<CefView> view)22 void CefScrollViewImpl::SetContentView(CefRefPtr<CefView> view) {
23   CEF_REQUIRE_VALID_RETURN_VOID();
24   DCHECK(view.get());
25   DCHECK(view->IsValid());
26   DCHECK(!view->IsAttached());
27   if (!view.get() || !view->IsValid() || view->IsAttached())
28     return;
29 
30   root_view()->SetContents(view_util::PassOwnership(view));
31 }
32 
GetContentView()33 CefRefPtr<CefView> CefScrollViewImpl::GetContentView() {
34   CEF_REQUIRE_VALID_RETURN(nullptr);
35   return view_util::GetFor(root_view()->contents(), false);
36 }
37 
GetVisibleContentRect()38 CefRect CefScrollViewImpl::GetVisibleContentRect() {
39   CEF_REQUIRE_VALID_RETURN(CefRect());
40   const gfx::Rect& rect = root_view()->GetVisibleRect();
41   return CefRect(rect.x(), rect.y(), rect.width(), rect.height());
42 }
43 
HasHorizontalScrollbar()44 bool CefScrollViewImpl::HasHorizontalScrollbar() {
45   CEF_REQUIRE_VALID_RETURN(false);
46   const views::ScrollBar* scrollbar = root_view()->horizontal_scroll_bar();
47   return scrollbar && scrollbar->GetVisible();
48 }
49 
GetHorizontalScrollbarHeight()50 int CefScrollViewImpl::GetHorizontalScrollbarHeight() {
51   CEF_REQUIRE_VALID_RETURN(0);
52   return root_view()->GetScrollBarLayoutHeight();
53 }
54 
HasVerticalScrollbar()55 bool CefScrollViewImpl::HasVerticalScrollbar() {
56   CEF_REQUIRE_VALID_RETURN(false);
57   const views::ScrollBar* scrollbar = root_view()->vertical_scroll_bar();
58   return scrollbar && scrollbar->GetVisible();
59 }
60 
GetVerticalScrollbarWidth()61 int CefScrollViewImpl::GetVerticalScrollbarWidth() {
62   CEF_REQUIRE_VALID_RETURN(0);
63   return root_view()->GetScrollBarLayoutWidth();
64 }
65 
GetDebugInfo(base::DictionaryValue * info,bool include_children)66 void CefScrollViewImpl::GetDebugInfo(base::DictionaryValue* info,
67                                      bool include_children) {
68   ParentClass::GetDebugInfo(info, include_children);
69   if (include_children) {
70     views::View* view = root_view()->contents();
71     CefViewAdapter* adapter = CefViewAdapter::GetFor(view);
72     if (adapter) {
73       std::unique_ptr<base::DictionaryValue> child_info(
74           new base::DictionaryValue());
75       adapter->GetDebugInfo(child_info.get(), include_children);
76       info->Set("content_view", std::move(child_info));
77     }
78   }
79 }
80 
CefScrollViewImpl(CefRefPtr<CefViewDelegate> delegate)81 CefScrollViewImpl::CefScrollViewImpl(CefRefPtr<CefViewDelegate> delegate)
82     : ParentClass(delegate) {}
83 
CreateRootView()84 CefScrollViewView* CefScrollViewImpl::CreateRootView() {
85   return new CefScrollViewView(delegate());
86 }
87 
InitializeRootView()88 void CefScrollViewImpl::InitializeRootView() {
89   static_cast<CefScrollViewView*>(root_view())->Initialize();
90 }
91