1 // Copyright (c) 2010 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. 4 5 #ifndef PDF_FADING_CONTROLS_H_ 6 #define PDF_FADING_CONTROLS_H_ 7 8 #include <list> 9 10 #include "pdf/control.h" 11 12 namespace chrome_pdf { 13 14 class FadingControls : public Control, 15 public ControlOwner { 16 public: 17 enum FadingState { 18 NONE, 19 FADING_IN, 20 FADING_OUT 21 }; 22 23 FadingControls(); 24 virtual ~FadingControls(); 25 virtual bool CreateFadingControls( 26 uint32 id, const pp::Rect& rc, bool visible, 27 Control::Owner* delegate, uint8 transparency); 28 29 // Control interface. 30 virtual void Paint(pp::ImageData* image_data, const pp::Rect& rc); 31 virtual bool HandleEvent(const pp::InputEvent& event); 32 virtual void OnTimerFired(uint32 timer_id); 33 virtual void EventCaptureReleased(); 34 virtual void MoveBy(const pp::Point& offset, bool invalidate); 35 36 // ControlOwner interface. 37 virtual void OnEvent(uint32 control_id, uint32 event_id, void* data); 38 virtual void Invalidate(uint32 control_id, const pp::Rect& rc); 39 virtual uint32 ScheduleTimer(uint32 control_id, uint32 timeout_ms); 40 virtual void SetEventCapture(uint32 control_id, bool set_capture); 41 virtual void SetCursor(uint32 control_id, PP_CursorType_Dev cursor_type); 42 virtual pp::Instance* GetInstance(); 43 44 // FadingControls interface 45 // This function takes ownership of the control, and will destoy it 46 // when control is destroyed. 47 // Input control MUST be located inside FadingControls boundaries, and has 48 // this instance of FadingControls as a delegate. 49 virtual bool AddControl(Control* control); 50 virtual void RemoveControl(uint32 control_id); 51 virtual Control* GetControl(uint32 id); 52 virtual pp::Rect GetControlsRect(); 53 54 // Expand/Shrink area which triggers inner control appearance to the left. 55 virtual bool ExpandLeft(int offset); 56 57 // Fade-in, then show controls for time_ms, and then fade-out. Any mouse 58 // event in this control area will interrupt splash mode. 59 virtual void Splash(uint32 time_ms); 60 current_transparency()61 uint8 current_transparency() const { return current_transparency_; } 62 63 private: 64 bool NotifyControls(const pp::InputEvent& event); 65 void FadeIn(); 66 void FadeOut(); 67 void OnFadingComplete(); 68 void CancelSplashMode(); 69 70 std::list<Control*> controls_; 71 FadingState state_; 72 uint8 current_transparency_; 73 uint32 fading_timer_id_; 74 uint32 current_capture_control_; 75 uint32 fading_timeout_; 76 uint32 alpha_shift_; 77 bool splash_; 78 uint32 splash_timeout_; 79 }; 80 81 } // namespace chrome_pdf 82 83 #endif // PDF_FADING_CONTROLS_H_ 84 85