| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 5 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/view_ids.h" | 7 #include "chrome/browser/ui/view_ids.h" |
| 8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 8 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 9 #include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h
" | 9 #include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h
" |
| 10 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
| 11 #include "chrome/grit/theme_resources.h" | 11 #include "chrome/grit/theme_resources.h" |
| 12 #include "components/grit/components_scaled_resources.h" | 12 #include "components/grit/components_scaled_resources.h" |
| 13 #include "components/omnibox/browser/omnibox_edit_model.h" | 13 #include "components/omnibox/browser/omnibox_edit_model.h" |
| 14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/views/animation/ink_drop_impl.h" |
| 16 #include "ui/views/controls/label.h" | 17 #include "ui/views/controls/label.h" |
| 17 | 18 |
| 18 using content::WebContents; | 19 using content::WebContents; |
| 19 | 20 |
| 20 LocationIconView::LocationIconView(const gfx::FontList& font_list, | 21 LocationIconView::LocationIconView(const gfx::FontList& font_list, |
| 21 LocationBarView* location_bar) | 22 LocationBarView* location_bar) |
| 22 : IconLabelBubbleView(font_list, true), | 23 : IconLabelBubbleView(font_list, true), |
| 23 suppress_mouse_released_action_(false), | 24 suppress_mouse_released_action_(false), |
| 24 location_bar_(location_bar), | 25 location_bar_(location_bar), |
| 25 animation_(this) { | 26 animation_(this) { |
| 26 set_id(VIEW_ID_LOCATION_ICON); | 27 set_id(VIEW_ID_LOCATION_ICON); |
| 28 SetInkDropMode(InkDropMode::ON); |
| 27 | 29 |
| 28 #if defined(OS_MACOSX) | 30 #if defined(OS_MACOSX) |
| 29 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 31 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
| 30 #else | 32 #else |
| 31 SetFocusBehavior(FocusBehavior::ALWAYS); | 33 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 32 #endif | 34 #endif |
| 33 | 35 |
| 34 animation_.SetSlideDuration(kOpenTimeMS); | 36 animation_.SetSlideDuration(kOpenTimeMS); |
| 35 } | 37 } |
| 36 | 38 |
| 37 LocationIconView::~LocationIconView() { | 39 LocationIconView::~LocationIconView() { |
| 38 } | 40 } |
| 39 | 41 |
| 42 bool LocationIconView::IsInkDropEnabled() const { |
| 43 return !location_bar_->GetOmniboxView()->IsEditingOrEmpty(); |
| 44 } |
| 45 |
| 40 gfx::Size LocationIconView::GetMinimumSize() const { | 46 gfx::Size LocationIconView::GetMinimumSize() const { |
| 41 return GetMinimumSizeForPreferredSize(GetPreferredSize()); | 47 return GetMinimumSizeForPreferredSize(GetPreferredSize()); |
| 42 } | 48 } |
| 43 | 49 |
| 44 bool LocationIconView::OnMousePressed(const ui::MouseEvent& event) { | 50 bool LocationIconView::OnMousePressed(const ui::MouseEvent& event) { |
| 45 if (event.IsOnlyMiddleMouseButton() && | 51 if (event.IsOnlyMiddleMouseButton() && |
| 46 ui::Clipboard::IsSupportedClipboardType(ui::CLIPBOARD_TYPE_SELECTION)) { | 52 ui::Clipboard::IsSupportedClipboardType(ui::CLIPBOARD_TYPE_SELECTION)) { |
| 47 base::string16 text; | 53 base::string16 text; |
| 48 ui::Clipboard::GetForCurrentThread()->ReadText( | 54 ui::Clipboard::GetForCurrentThread()->ReadText( |
| 49 ui::CLIPBOARD_TYPE_SELECTION, &text); | 55 ui::CLIPBOARD_TYPE_SELECTION, &text); |
| 50 text = OmniboxView::SanitizeTextForPaste(text); | 56 text = OmniboxView::SanitizeTextForPaste(text); |
| 51 OmniboxEditModel* model = location_bar_->GetOmniboxView()->model(); | 57 OmniboxEditModel* model = location_bar_->GetOmniboxView()->model(); |
| 52 if (model->CanPasteAndGo(text)) | 58 if (model->CanPasteAndGo(text)) |
| 53 model->PasteAndGo(text); | 59 model->PasteAndGo(text); |
| 54 } | 60 } |
| 55 | 61 |
| 56 suppress_mouse_released_action_ = | 62 suppress_mouse_released_action_ = |
| 57 WebsiteSettingsPopupView::GetShownPopupType() != | 63 WebsiteSettingsPopupView::GetShownPopupType() != |
| 58 WebsiteSettingsPopupView::POPUP_NONE; | 64 WebsiteSettingsPopupView::POPUP_NONE; |
| 65 |
| 66 if (!suppress_mouse_released_action_) |
| 67 IconLabelBubbleView::OnMousePressed(event); |
| 68 |
| 59 return true; | 69 return true; |
| 60 } | 70 } |
| 61 | 71 |
| 62 bool LocationIconView::OnMouseDragged(const ui::MouseEvent& event) { | 72 bool LocationIconView::OnMouseDragged(const ui::MouseEvent& event) { |
| 63 location_bar_->GetOmniboxView()->CloseOmniboxPopup(); | 73 location_bar_->GetOmniboxView()->CloseOmniboxPopup(); |
| 64 return false; | 74 return false; |
| 65 } | 75 } |
| 66 | 76 |
| 67 void LocationIconView::OnMouseReleased(const ui::MouseEvent& event) { | 77 void LocationIconView::OnMouseReleased(const ui::MouseEvent& event) { |
| 68 if (event.IsOnlyMiddleMouseButton()) | 78 if (event.IsOnlyMiddleMouseButton()) |
| 69 return; | 79 return; |
| 70 | 80 |
| 71 // If this is the second click on this view then the bubble was showing on | 81 // If this is the second click on this view then the bubble was showing on |
| 72 // the mouse pressed event and is hidden now. Prevent the bubble from | 82 // the mouse pressed event and is hidden now. Prevent the bubble from |
| 73 // reshowing by doing nothing here. | 83 // reshowing by doing nothing here. |
| 74 if (suppress_mouse_released_action_) { | 84 if (suppress_mouse_released_action_) { |
| 75 suppress_mouse_released_action_ = false; | 85 suppress_mouse_released_action_ = false; |
| 76 return; | 86 return; |
| 77 } | 87 } |
| 78 | 88 |
| 79 OnClickOrTap(event); | 89 OnClickOrTap(event); |
| 90 IconLabelBubbleView::OnMouseReleased(event); |
| 80 } | 91 } |
| 81 | 92 |
| 82 void LocationIconView::OnGestureEvent(ui::GestureEvent* event) { | 93 void LocationIconView::OnGestureEvent(ui::GestureEvent* event) { |
| 83 if (event->type() != ui::ET_GESTURE_TAP) | 94 if (event->type() != ui::ET_GESTURE_TAP) |
| 84 return; | 95 return; |
| 85 OnClickOrTap(*event); | 96 OnClickOrTap(*event); |
| 86 event->SetHandled(); | 97 event->SetHandled(); |
| 87 } | 98 } |
| 88 | 99 |
| 89 bool LocationIconView::GetTooltipText(const gfx::Point& p, | 100 bool LocationIconView::GetTooltipText(const gfx::Point& p, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 return size; | 163 return size; |
| 153 } | 164 } |
| 154 | 165 |
| 155 void LocationIconView::OnClickOrTap(const ui::LocatedEvent& event) { | 166 void LocationIconView::OnClickOrTap(const ui::LocatedEvent& event) { |
| 156 // Do not show page info if the user has been editing the location bar or the | 167 // Do not show page info if the user has been editing the location bar or the |
| 157 // location bar is at the NTP. | 168 // location bar is at the NTP. |
| 158 if (location_bar_->GetOmniboxView()->IsEditingOrEmpty()) | 169 if (location_bar_->GetOmniboxView()->IsEditingOrEmpty()) |
| 159 return; | 170 return; |
| 160 ProcessLocatedEvent(event); | 171 ProcessLocatedEvent(event); |
| 161 } | 172 } |
| OLD | NEW |