1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h"
7 #include "chrome/browser/ui/views/open_pdf_in_reader_bubble_view.h"
8 #include "chrome/grit/generated_resources.h"
9 #include "components/pdf/browser/open_pdf_in_reader_prompt_client.h"
10 #include "components/pdf/browser/pdf_web_contents_helper.h"
11 #include "grit/theme_resources.h"
12 #include "ui/accessibility/ax_view_state.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/views/widget/widget.h"
17 OpenPDFInReaderView::OpenPDFInReaderView() : bubble_(NULL
), model_(NULL
) {
18 SetAccessibilityFocusable(true);
19 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
20 IDR_OMNIBOX_PDF_ICON
));
21 SetTooltipText(l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_OPEN_IN_READER_LINK
));
24 OpenPDFInReaderView::~OpenPDFInReaderView() {
26 bubble_
->GetWidget()->RemoveObserver(this);
29 void OpenPDFInReaderView::Update(content::WebContents
* web_contents
) {
32 pdf::PDFWebContentsHelper
* pdf_tab_helper
=
33 pdf::PDFWebContentsHelper::FromWebContents(web_contents
);
34 model_
= pdf_tab_helper
->open_in_reader_prompt();
40 void OpenPDFInReaderView::ShowBubble() {
45 bubble_
= new OpenPDFInReaderBubbleView(this, model_
);
46 views::BubbleDelegateView::CreateBubble(bubble_
);
47 bubble_
->GetWidget()->AddObserver(this);
48 bubble_
->GetWidget()->Show();
51 void OpenPDFInReaderView::GetAccessibleState(ui::AXViewState
* state
) {
52 state
->name
= l10n_util::GetStringUTF16(IDS_ACCNAME_OPEN_PDF_IN_READER
);
53 state
->role
= ui::AX_ROLE_BUTTON
;
56 bool OpenPDFInReaderView::OnMousePressed(const ui::MouseEvent
& event
) {
57 // Show the bubble on mouse release; that is standard button behavior.
61 void OpenPDFInReaderView::OnMouseReleased(const ui::MouseEvent
& event
) {
62 if (event
.IsOnlyLeftMouseButton() && HitTestPoint(event
.location()))
66 bool OpenPDFInReaderView::OnKeyPressed(const ui::KeyEvent
& event
) {
67 if (event
.key_code() != ui::VKEY_SPACE
&&
68 event
.key_code() != ui::VKEY_RETURN
) {
76 void OpenPDFInReaderView::OnWidgetDestroying(views::Widget
* widget
) {
80 bubble_
->GetWidget()->RemoveObserver(this);