Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / location_bar / open_pdf_in_reader_view.cc
blob68c4e012f009e6c6ab1454842ffe5e7b274e7d8f
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/pdf/pdf_tab_helper.h"
8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
9 #include "chrome/browser/ui/views/open_pdf_in_reader_bubble_view.h"
10 #include "grit/generated_resources.h"
11 #include "grit/theme_resources.h"
12 #include "ui/base/accessibility/accessible_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(LocationBarView* location_bar_view)
18 : location_bar_view_(location_bar_view),
19 bubble_(NULL),
20 model_(NULL) {
21 SetAccessibilityFocusable(true);
22 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
23 IDR_OMNIBOX_PDF_ICON));
24 SetTooltipText(l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_OPEN_IN_READER_LINK));
25 LocationBarView::InitTouchableLocationBarChildView(this);
28 OpenPDFInReaderView::~OpenPDFInReaderView() {
29 if (bubble_)
30 bubble_->GetWidget()->RemoveObserver(this);
33 void OpenPDFInReaderView::Update(content::WebContents* web_contents) {
34 model_ = NULL;
35 if (web_contents) {
36 PDFTabHelper* pdf_tab_helper = PDFTabHelper::FromWebContents(web_contents);
37 model_ = pdf_tab_helper->open_in_reader_prompt();
40 SetVisible(!!model_);
43 void OpenPDFInReaderView::ShowBubble() {
44 if (bubble_)
45 return;
47 DCHECK(model_);
48 bubble_ = new OpenPDFInReaderBubbleView(this, model_);
49 views::BubbleDelegateView::CreateBubble(bubble_);
50 bubble_->GetWidget()->AddObserver(this);
51 bubble_->GetWidget()->Show();
54 void OpenPDFInReaderView::GetAccessibleState(ui::AccessibleViewState* state) {
55 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_OPEN_PDF_IN_READER);
56 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
59 bool OpenPDFInReaderView::OnMousePressed(const ui::MouseEvent& event) {
60 // Show the bubble on mouse release; that is standard button behavior.
61 return true;
64 void OpenPDFInReaderView::OnMouseReleased(const ui::MouseEvent& event) {
65 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location()))
66 ShowBubble();
69 bool OpenPDFInReaderView::OnKeyPressed(const ui::KeyEvent& event) {
70 if (event.key_code() != ui::VKEY_SPACE &&
71 event.key_code() != ui::VKEY_RETURN) {
72 return false;
75 ShowBubble();
76 return true;
79 void OpenPDFInReaderView::OnWidgetDestroying(views::Widget* widget) {
80 if (!bubble_)
81 return;
83 bubble_->GetWidget()->RemoveObserver(this);
84 bubble_ = NULL;