File: zoom_view.cc

package info (click to toggle)
chromium-browser 70.0.3538.110-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,619,476 kB
  • sloc: cpp: 13,024,755; ansic: 1,349,823; python: 916,672; xml: 314,489; java: 280,047; asm: 276,936; perl: 75,771; objc: 66,634; sh: 45,860; cs: 28,354; php: 11,064; makefile: 10,911; yacc: 9,109; tcl: 8,403; ruby: 4,065; lex: 1,779; pascal: 1,411; lisp: 1,055; awk: 41; jsp: 39; sed: 17; sql: 3
file content (103 lines) | stat: -rw-r--r-- 3,365 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/page_action/zoom_view.h"

#include "base/i18n/number_formatting.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
#include "chrome/grit/generated_resources.h"
#include "components/toolbar/toolbar_model.h"
#include "components/zoom/zoom_controller.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/events/event.h"
#include "ui/gfx/geometry/size.h"

ZoomView::ZoomView(LocationBarView::Delegate* location_bar_delegate,
                   PageActionIconView::Delegate* delegate)
    : PageActionIconView(nullptr, 0, delegate),
      location_bar_delegate_(location_bar_delegate),
      icon_(&kZoomMinusIcon) {
  SetVisible(false);
}

ZoomView::~ZoomView() {}

bool ZoomView::Update() {
  bool was_visible = visible();
  ZoomChangedForActiveTab(false);
  return visible() != was_visible;
}

bool ZoomView::ShouldBeVisible(bool can_show_bubble) const {
  if (location_bar_delegate_ &&
      location_bar_delegate_->GetToolbarModel()->input_in_progress()) {
    return false;
  }

  if (can_show_bubble)
    return true;

  if (ZoomBubbleView::GetZoomBubble())
    return true;

  DCHECK(GetWebContents());
  zoom::ZoomController* zoom_controller =
      zoom::ZoomController::FromWebContents(GetWebContents());
  return zoom_controller && !zoom_controller->IsAtDefaultZoom();
}

void ZoomView::ZoomChangedForActiveTab(bool can_show_bubble) {
  content::WebContents* web_contents = GetWebContents();
  if (!web_contents)
    return;

  if (ShouldBeVisible(can_show_bubble)) {
    zoom::ZoomController* zoom_controller =
        zoom::ZoomController::FromWebContents(web_contents);
    current_zoom_percent_ = zoom_controller->GetZoomPercent();

    // The icon is hidden when the zoom level is default.
    icon_ = zoom_controller && zoom_controller->GetZoomRelativeToDefault() ==
                                   zoom::ZoomController::ZOOM_BELOW_DEFAULT_ZOOM
                ? &kZoomMinusIcon
                : &kZoomPlusIcon;
    if (GetNativeTheme())
      UpdateIconImage();

    // Visibility must be enabled before the bubble is shown to ensure the
    // bubble anchors correctly.
    SetVisible(true);

    if (can_show_bubble) {
      ZoomBubbleView::ShowBubble(web_contents, gfx::Point(),
                                 ZoomBubbleView::AUTOMATIC);
    } else {
      ZoomBubbleView::RefreshBubbleIfShowing(web_contents);
    }
  } else {
    SetVisible(false);
    ZoomBubbleView::CloseCurrentBubble();
  }
}

void ZoomView::OnExecuting(PageActionIconView::ExecuteSource source) {
  ZoomBubbleView::ShowBubble(GetWebContents(), gfx::Point(),
                             ZoomBubbleView::USER_GESTURE);
}

views::BubbleDialogDelegateView* ZoomView::GetBubble() const {
  return ZoomBubbleView::GetZoomBubble();
}

const gfx::VectorIcon& ZoomView::GetVectorIcon() const {
  return *icon_;
}

base::string16 ZoomView::GetTextForTooltipAndAccessibleName() const {
  return l10n_util::GetStringFUTF16(IDS_TOOLTIP_ZOOM,
                                    base::FormatPercent(current_zoom_percent_));
}