| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/go_button.h" | 5 #include "chrome/browser/views/go_button.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
| 11 #include "chrome/browser/browser.h" | 11 #include "chrome/browser/browser.h" |
| 12 #include "chrome/browser/profile.h" | 12 #include "chrome/browser/profile.h" |
| 13 #include "chrome/browser/search_engines/template_url_model.h" | 13 #include "chrome/browser/search_engines/template_url_model.h" |
| 14 #include "chrome/browser/views/event_utils.h" | 14 #include "chrome/browser/views/event_utils.h" |
| 15 #include "chrome/browser/views/location_bar_view.h" | 15 #include "chrome/browser/views/location_bar_view.h" |
| 16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 17 | 17 |
| 18 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
| 19 // GoButton, public: | 19 // GoButton, public: |
| 20 | 20 |
| 21 GoButton::GoButton(LocationBarView* location_bar, Browser* browser) | 21 GoButton::GoButton(LocationBarView* location_bar, Browser* browser) |
| 22 : ToggleImageButton(this), | 22 : ToggleImageButton(this), |
| 23 button_delay_(0), | |
| 24 ALLOW_THIS_IN_INITIALIZER_LIST(stop_timer_(this)), | 23 ALLOW_THIS_IN_INITIALIZER_LIST(stop_timer_(this)), |
| 25 location_bar_(location_bar), | 24 location_bar_(location_bar), |
| 26 browser_(browser), | 25 browser_(browser), |
| 27 intended_mode_(MODE_GO), | 26 intended_mode_(MODE_GO), |
| 28 visible_mode_(MODE_GO) { | 27 visible_mode_(MODE_GO) { |
| 29 DCHECK(location_bar_); | 28 DCHECK(location_bar_); |
| 30 set_triggerable_event_flags(views::Event::EF_LEFT_BUTTON_DOWN | | 29 set_triggerable_event_flags(views::Event::EF_LEFT_BUTTON_DOWN | |
| 31 views::Event::EF_MIDDLE_BUTTON_DOWN); | 30 views::Event::EF_MIDDLE_BUTTON_DOWN); |
| 32 } | 31 } |
| 33 | 32 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 56 if (visible_mode_ == MODE_STOP) { | 55 if (visible_mode_ == MODE_STOP) { |
| 57 browser_->Stop(); | 56 browser_->Stop(); |
| 58 | 57 |
| 59 // The user has clicked, so we can feel free to update the button, | 58 // The user has clicked, so we can feel free to update the button, |
| 60 // even if the mouse is still hovering. | 59 // even if the mouse is still hovering. |
| 61 ChangeMode(MODE_GO, true); | 60 ChangeMode(MODE_GO, true); |
| 62 } else if (visible_mode_ == MODE_GO && stop_timer_.empty()) { | 61 } else if (visible_mode_ == MODE_GO && stop_timer_.empty()) { |
| 63 // If the go button is visible and not within the double click timer, go. | 62 // If the go button is visible and not within the double click timer, go. |
| 64 browser_->Go(event_utils::DispositionFromEventFlags(mouse_event_flags())); | 63 browser_->Go(event_utils::DispositionFromEventFlags(mouse_event_flags())); |
| 65 | 64 |
| 66 // Figure out the system double-click time. | |
| 67 if (button_delay_ == 0) { | |
| 68 #if defined(OS_WIN) | |
| 69 button_delay_ = GetDoubleClickTime(); | |
| 70 #else | |
| 71 NOTIMPLEMENTED(); | |
| 72 button_delay_ = 500; | |
| 73 #endif | |
| 74 } | |
| 75 | |
| 76 // Stop any existing timers. | 65 // Stop any existing timers. |
| 77 stop_timer_.RevokeAll(); | 66 stop_timer_.RevokeAll(); |
| 78 | 67 |
| 79 // Start a timer - while this timer is running, the go button | 68 // Start a timer - while this timer is running, the go button |
| 80 // cannot be changed to a stop button. We do not set intended_mode_ | 69 // cannot be changed to a stop button. We do not set intended_mode_ |
| 81 // to MODE_STOP here as we want to wait for the browser to tell | 70 // to MODE_STOP here as we want to wait for the browser to tell |
| 82 // us that it has started loading (and this may occur only after | 71 // us that it has started loading (and this may occur only after |
| 83 // some delay). | 72 // some delay). |
| 84 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 73 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 85 stop_timer_.NewRunnableMethod(&GoButton::OnButtonTimer), | 74 stop_timer_.NewRunnableMethod(&GoButton::OnButtonTimer), |
| 86 button_delay_); | 75 GetDoubleClickTimeMS()); |
| 87 } | 76 } |
| 88 } | 77 } |
| 89 | 78 |
| 90 //////////////////////////////////////////////////////////////////////////////// | 79 //////////////////////////////////////////////////////////////////////////////// |
| 91 // GoButton, View overrides: | 80 // GoButton, View overrides: |
| 92 | 81 |
| 93 void GoButton::OnMouseExited(const views::MouseEvent& e) { | 82 void GoButton::OnMouseExited(const views::MouseEvent& e) { |
| 94 ChangeMode(intended_mode_, true); | 83 ChangeMode(intended_mode_, true); |
| 95 if (state() != BS_DISABLED) | 84 if (state() != BS_DISABLED) |
| 96 SetState(BS_NORMAL); | 85 SetState(BS_NORMAL); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 return true; | 126 return true; |
| 138 } | 127 } |
| 139 | 128 |
| 140 //////////////////////////////////////////////////////////////////////////////// | 129 //////////////////////////////////////////////////////////////////////////////// |
| 141 // GoButton, private: | 130 // GoButton, private: |
| 142 | 131 |
| 143 void GoButton::OnButtonTimer() { | 132 void GoButton::OnButtonTimer() { |
| 144 stop_timer_.RevokeAll(); | 133 stop_timer_.RevokeAll(); |
| 145 ChangeMode(intended_mode_, true); | 134 ChangeMode(intended_mode_, true); |
| 146 } | 135 } |
| OLD | NEW |