1ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen// Copyright (c) 2011 The Chromium Authors. All rights reserved. 24a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch// Use of this source code is governed by a BSD-style license that can be 34a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch// found in the LICENSE file. 44a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 54a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch#ifndef CHROME_BROWSER_UI_VIEWS_RELOAD_BUTTON_H__ 64a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch#define CHROME_BROWSER_UI_VIEWS_RELOAD_BUTTON_H__ 74a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch#pragma once 84a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 94a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch#include "base/basictypes.h" 104a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch#include "base/gtest_prod_util.h" 114a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch#include "base/timer.h" 124a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch#include "views/controls/button/image_button.h" 134a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 144a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdochclass Browser; 154a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdochclass LocationBarView; 164a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 174a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch//////////////////////////////////////////////////////////////////////////////// 184a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch// 194a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch// ReloadButton 204a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch// 214a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch// The reload button in the toolbar, which changes to a stop button when a page 224a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch// load is in progress. Trickiness comes from the desire to have the 'stop' 234a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch// button not change back to 'reload' if the user's mouse is hovering over it 244a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch// (to prevent mis-clicks). 254a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch// 264a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch//////////////////////////////////////////////////////////////////////////////// 274a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 284a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdochclass ReloadButton : public views::ToggleImageButton, 294a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch public views::ButtonListener { 304a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch public: 314a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch enum Mode { MODE_RELOAD = 0, MODE_STOP }; 324a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 334a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch ReloadButton(LocationBarView* location_bar, Browser* Browser); 344a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch virtual ~ReloadButton(); 354a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 364a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch // Ask for a specified button state. If |force| is true this will be applied 374a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch // immediately. 384a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch void ChangeMode(Mode mode, bool force); 394a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 404a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch // Overridden from views::ButtonListener: 414a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch virtual void ButtonPressed(views::Button* /* button */, 42ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen const views::Event& event) OVERRIDE; 434a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 444a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch // Overridden from views::View: 45ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; 46ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen virtual bool GetTooltipText(const gfx::Point& p, 47ddb351dbec246cf1fab5ec20d2d5520909041de1Kristian Monsen std::wstring* tooltip) OVERRIDE; 484a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 494a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch private: 504a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch friend class ReloadButtonTest; 514a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 524a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch void OnDoubleClickTimer(); 534a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch void OnStopToReloadTimer(); 544a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 554a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch base::OneShotTimer<ReloadButton> double_click_timer_; 564a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch base::OneShotTimer<ReloadButton> stop_to_reload_timer_; 574a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 584a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch // These may be NULL when testing. 594a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch LocationBarView* location_bar_; 604a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch Browser* browser_; 614a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 624a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch // The mode we should be in assuming no timers are running. 634a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch Mode intended_mode_; 644a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 654a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch // The currently-visible mode - this may differ from the intended mode. 664a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch Mode visible_mode_; 674a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 684a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch // The delay times for the timers. These are members so that tests can modify 694a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch // them. 704a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch base::TimeDelta double_click_timer_delay_; 714a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch base::TimeDelta stop_to_reload_timer_delay_; 724a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 734a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch // TESTING ONLY 744a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch // True if we should pretend the button is hovered. 754a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch bool testing_mouse_hovered_; 764a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch // Increments when we would tell the browser to "reload", so 774a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch // test code can tell whether we did so (as there may be no |browser_|). 784a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch int testing_reload_count_; 794a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 804a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch DISALLOW_IMPLICIT_CONSTRUCTORS(ReloadButton); 814a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch}; 824a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch 834a5e2dc747d50c653511c68ccb2cfbfb740bd5a7Ben Murdoch#endif // CHROME_BROWSER_UI_VIEWS_RELOAD_BUTTON_H__ 84