diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser.vcproj | 28 | ||||
-rw-r--r-- | chrome/browser/wizard/wizard.cc | 492 | ||||
-rw-r--r-- | chrome/browser/wizard/wizard.h | 152 | ||||
-rw-r--r-- | chrome/browser/wizard/wizard_step.h | 116 |
4 files changed, 6 insertions, 782 deletions
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index f560330..078f95f 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -810,27 +810,27 @@ > </File> <File - RelativePath=".\bookmarks\bookmark_model.cc" + RelativePath=".\bookmarks\bookmark_codec.cc" > </File> <File - RelativePath=".\bookmarks\bookmark_model.h" + RelativePath=".\bookmarks\bookmark_codec.h" > </File> <File - RelativePath=".\bookmarks\bookmark_codec.cc" + RelativePath=".\bookmarks\bookmark_drag_data.cc" > </File> <File - RelativePath=".\bookmarks\bookmark_codec.h" + RelativePath=".\bookmarks\bookmark_drag_data.h" > </File> <File - RelativePath=".\bookmarks\bookmark_drag_data.cc" + RelativePath=".\bookmarks\bookmark_model.cc" > </File> <File - RelativePath=".\bookmarks\bookmark_drag_data.h" + RelativePath=".\bookmarks\bookmark_model.h" > </File> <File @@ -1639,22 +1639,6 @@ </File> </Filter> <Filter - Name="Wizard" - > - <File - RelativePath=".\wizard\wizard.cc" - > - </File> - <File - RelativePath=".\wizard\wizard.h" - > - </File> - <File - RelativePath=".\wizard\wizard_step.h" - > - </File> - </Filter> - <Filter Name="Drag & Drop" > <File diff --git a/chrome/browser/wizard/wizard.cc b/chrome/browser/wizard/wizard.cc deleted file mode 100644 index c566f53..0000000 --- a/chrome/browser/wizard/wizard.cc +++ /dev/null @@ -1,492 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/wizard/wizard.h" - -#include <math.h> - -#include "base/logging.h" -#include "chrome/browser/wizard/wizard_step.h" -#include "chrome/browser/standard_layout.h" - -#include "chrome/common/l10n_util.h" -#include "chrome/common/resource_bundle.h" -#include "chrome/common/stl_util-inl.h" - -#include "chrome/views/accelerator.h" -#include "chrome/views/label.h" -#include "chrome/views/native_button.h" - -#include "generated_resources.h" - -#include "SkBitmap.h" - -static const int kMinButtonWidth = 100; -static const int kWizardWidth = 400; -static const int kWizardHeight = 300; - -//////////////////////////////////////////////////////////////////////////////// -// -// WizardView is the Wizard top level view -// -//////////////////////////////////////////////////////////////////////////////// -class WizardView : public ChromeViews::View, - public ChromeViews::NativeButton::Listener { - public: - - WizardView(Wizard* owner) - : owner_(owner), - contents_(NULL), - custom_navigation_descriptor_(NULL) { - title_ = new ChromeViews::Label(L""); - title_->SetHorizontalAlignment(ChromeViews::Label::ALIGN_LEFT); - title_->SetFont( - ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::LargeFont)); - AddChildView(title_); - - cancel_ = - new ChromeViews::NativeButton(l10n_util::GetString(IDS_WIZARD_CANCEL)); - AddChildView(cancel_); - cancel_->SetListener(this); - ChromeViews::Accelerator accelerator(VK_ESCAPE, false, false, false); - cancel_->AddAccelerator(accelerator); - - previous_ = new ChromeViews::NativeButton( - l10n_util::GetString(IDS_WIZARD_PREVIOUS)); - AddChildView(previous_); - previous_->SetListener(this); - - next_ = new ChromeViews::NativeButton(l10n_util::GetString(IDS_WIZARD_NEXT)); - AddChildView(next_); - next_->SetListener(this); - } - - virtual ~WizardView() { - // Views provided by WizardStep instances are owned by the step - if (contents_) { - RemoveChildView(contents_); - contents_ = NULL; - } - - // Sub views are deleted by the view system - } - - void ComputeButtonSize(int* width, int *height) { - *width = kMinButtonWidth; - CSize s; - cancel_->GetPreferredSize(&s); - *height = s.cy; - *width = std::max(*width, static_cast<int>(s.cx)); - - previous_->GetPreferredSize(&s); - *width = std::max(*width, static_cast<int>(s.cx)); - *height = std::max(*height, static_cast<int>(s.cy)); - - next_->GetPreferredSize(&s); - *width = std::max(*width, static_cast<int>(s.cx)); - *height = std::max(*height, static_cast<int>(s.cy)); - } - - virtual void Layout() { - View* parent = GetParent(); - DCHECK(parent); - if (!parent) - return; - - if (title_->GetText().empty()) { - title_->SetBounds(0, 0, 0, 0); - title_->SetVisible(false); - } else { - CSize s; - title_->SetVisible(true); - title_->GetPreferredSize(&s); - title_->SetBounds(kPanelHorizMargin, kPanelVertMargin, - GetWidth() - (2 * kPanelVertMargin), - s.cy); - } - - int bw, bh; - ComputeButtonSize(&bw, &bh); - - int button_y = GetHeight() - kPanelVertMargin - bh; - cancel_->SetBounds(kPanelHorizMargin, button_y, bw, bh); - next_->SetBounds(GetWidth() - kPanelHorizMargin - bw, button_y, bw, bh); - previous_->SetBounds(next_->GetX() - kPanelHorizMargin - bw, button_y, bw, bh); - - if (contents_) { - int y = title_->GetY() + title_->GetHeight() + kPanelVertMargin; - contents_->SetBounds(kPanelHorizMargin, y, - GetWidth() - (2 * kPanelHorizMargin), - cancel_->GetY() - kPanelVertMargin - y); - contents_->Layout(); - } - } - - virtual void GetPreferredSize(CSize* out) { - CSize s; - int w = 0, h = 0; - - if (contents_) { - int extra_margin = (2 * kPanelVertMargin); - contents_->GetPreferredSize(&s); - w = s.cx; - h = s.cy + extra_margin; - } - - if (!title_->GetText().empty()) { - title_->GetPreferredSize(&s); - w = std::max(w, static_cast<int>(s.cx)); - h += s.cy; - } - - int bw, bh; - ComputeButtonSize(&bw, &bh); - h += bh; - - w += (2 * kPanelHorizMargin); - h += (2 * kPanelVertMargin); - out->cx = std::max(kWizardWidth, w); - out->cy = std::max(kWizardHeight, h); - } - - virtual void ButtonPressed(ChromeViews::NativeButton *sender) { - if (sender == cancel_) - owner_->Cancel(); - else if (sender == next_) - owner_->SelectNextStep(); - else if (sender == previous_) - owner_->SelectPreviousStep(); - } - - typedef enum { - FIRST_STEP_STYLE, - NORMAL_STEP_STYLE, - LAST_STEP_STYLE, - CUSTOM_STYLE - } ContentsStyle; - - void SetContents(ChromeViews::View* v, ContentsStyle s) { - if (contents_) - RemoveChildView(contents_); - custom_navigation_descriptor_ = NULL; - contents_ = v; - - // Note: we change the navigation button only if a view is provided. - // if |v| is NULL, this wizard is closing and updating anything may - // cause a flash. - if (contents_) { - switch (s) { - case FIRST_STEP_STYLE: - previous_->SetVisible(false); - next_->SetVisible(true); - next_->SetLabel(l10n_util::GetString(IDS_WIZARD_NEXT)); - break; - case NORMAL_STEP_STYLE: - previous_->SetVisible(true); - next_->SetVisible(true); - next_->SetLabel(l10n_util::GetString(IDS_WIZARD_NEXT)); - break; - case LAST_STEP_STYLE: - previous_->SetVisible(true); - next_->SetVisible(true); - next_->SetLabel(l10n_util::GetString(IDS_WIZARD_DONE)); - break; - } - AddChildView(contents_); - cancel_->SetVisible(true); - - // Reset the button labels to the default values. - previous_->SetLabel(l10n_util::GetString(IDS_WIZARD_PREVIOUS)); - next_->SetLabel(l10n_util::GetString(IDS_WIZARD_NEXT)); - } - } - - void SetTitle(const std::wstring& title) { - title_->SetText(title); - } - - void NavigationDescriptorChanged() { - if (custom_navigation_descriptor_) { - SetCustomNavigationDescriptor(custom_navigation_descriptor_); - } - } - - void SetCustomNavigationDescriptor(WizardNavigationDescriptor* wnd) { - custom_navigation_descriptor_ = wnd; - if (wnd->custom_default_button_) { - if (wnd->default_label_.empty()) { - next_->SetVisible(false); - } else { - next_->SetVisible(true); - next_->SetLabel(wnd->default_label_); - } - } - - if (wnd->custom_alternate_button_) { - if (wnd->alternate_label_.empty()) { - previous_->SetVisible(false); - } else { - previous_->SetVisible(true); - previous_->SetLabel(wnd->alternate_label_); - } - } - - cancel_->SetVisible(wnd->can_cancel_); - } - - WizardNavigationDescriptor* GetCustomNavigationDescriptor() { - return custom_navigation_descriptor_; - } - - void EnableNextButton(bool f) { - if (next_) - next_->SetEnabled(f); - } - - bool IsNextButtonEnabled() { - if (next_) - return next_->IsEnabled(); - else - return false; - } - - void EnablePreviousButton(bool f) { - if (previous_) - previous_->SetEnabled(f); - } - - bool IsPreviousButtonEnabled() { - if (previous_) - return previous_->IsEnabled(); - else - return false; - } - private: - - ChromeViews::Label* title_; - ChromeViews::NativeButton* next_; - ChromeViews::NativeButton* previous_; - ChromeViews::NativeButton* cancel_; - ChromeViews::View* contents_; - WizardNavigationDescriptor* custom_navigation_descriptor_; - - Wizard* owner_; - DISALLOW_EVIL_CONSTRUCTORS(WizardView); -}; - -//////////////////////////////////////////////////////////////////////////////// -// -// Wizard implementation -// -//////////////////////////////////////////////////////////////////////////////// - -Wizard::Wizard(WizardDelegate* d) : delegate_(d), - view_(NULL), - state_(NULL), - selected_step_(-1), - is_running_(false) { -} - -Wizard::~Wizard() { - Abort(); - delete view_; - RemoveAllSteps(); - - delete state_; - - STLDeleteContainerPairSecondPointers(images_.begin(), images_.end()); -} - -void Wizard::SetState(DictionaryValue* state) { - delete state_; - state_ = state; -} - -DictionaryValue* Wizard::GetState() { - return state_; -} - -void Wizard::AddStep(WizardStep* s) { - steps_.push_back(s); -} - -int Wizard::GetStepCount() const { - return static_cast<int>(steps_.size()); -} - -WizardStep* Wizard::GetStepAt(int index) { - DCHECK(index >= 0 && index < static_cast<int>(steps_.size())); - return steps_[index]; -} - -void Wizard::RemoveAllSteps() { - DCHECK(!is_running_); - - int c = static_cast<int>(steps_.size()); - while (--c >= 0) - steps_[c]->Dispose(); - steps_.clear(); -} - -ChromeViews::View* Wizard::GetTopLevelView() { - if (!view_) { - view_ = new WizardView(this); - // We own the view and it should never be deleted by the parent - // view - view_->SetParentOwned(false); - } - return view_; -} - -void Wizard::Start() { - DCHECK(view_ && view_->GetParent()); - DCHECK(steps_.size() > 0); - DCHECK(!is_running_); - is_running_ = true; - SelectStepAt(0); - view_->Layout(); -} - -void Wizard::Reset() { - is_running_ = false; - if (selected_step_ != -1) - steps_[selected_step_]->WillBecomeInvisible(this, - WizardStep::CANCEL_ACTION); - selected_step_ = -1; - view_->EnableNextButton(true); - view_->EnablePreviousButton(true); - view_->SetContents(NULL, WizardView::NORMAL_STEP_STYLE); - - if (view_->GetParent()) - view_->GetParent()->RemoveChildView(view_); -} - -void Wizard::WizardDone(bool commit) { - if (is_running_) { - Reset(); - is_running_ = false; - if (delegate_) - delegate_->WizardClosed(commit); - } -} - -void Wizard::Abort() { - WizardDone(false); -} - -// Note: this private method doesn't call WillBecomeInvisible because -// it needs to be called before deciding what step to select next. -void Wizard::SelectStepAt(int index) { - DCHECK(index >= 0 && index < static_cast<int>(steps_.size())); - - if (index == selected_step_) - return; - - selected_step_ = index; - - WizardView::ContentsStyle style = WizardView::NORMAL_STEP_STYLE; - if (selected_step_ == 0) - style = WizardView::FIRST_STEP_STYLE; - else if (selected_step_ == (static_cast<int>(steps_.size()) - 1)) - style = WizardView::LAST_STEP_STYLE; - - view_->SetContents(steps_[selected_step_]->GetView(this), style); - steps_[selected_step_]->DidBecomeVisible(this); - WizardNavigationDescriptor* wnd = - steps_[selected_step_]->GetNavigationDescriptor(); - if (wnd) - view_->SetCustomNavigationDescriptor(wnd); - view_->SetTitle(steps_[selected_step_]->GetTitle(this)); - - CSize s; - view_->GetPreferredSize(&s); - if (view_->GetWidth() != s.cx || view_->GetHeight() != s.cy) - delegate_->ResizeTopLevelView(s.cx, s.cy); - view_->Layout(); - view_->SchedulePaint(); -} - -void Wizard::NavigationDescriptorChanged() { - view_->NavigationDescriptorChanged(); -} - -void Wizard::Cancel() { - Abort(); -} - -void Wizard::SelectStep(bool is_forward) { - int delta = is_forward ? 1 : -1; - WizardNavigationDescriptor* wnd = view_->GetCustomNavigationDescriptor(); - if (wnd) { - if (is_forward && wnd->custom_default_button_) - delta = wnd->default_offset_; - else if (!is_forward && wnd->custom_alternate_button_) - delta = wnd->alternate_offset_; - } - - if (selected_step_ != -1) { - steps_[selected_step_]->WillBecomeInvisible( - this, is_forward ? WizardStep::DEFAULT_ACTION : - WizardStep::ALTERNATE_ACTION); - } - - bool step_selected = false; - int i; - for (i = selected_step_ + delta; - i >= 0 && i < static_cast<int>(steps_.size()); i += delta) { - if (steps_[i]->IsEnabledFor(this)) { - SelectStepAt(i); - step_selected = true; - break; - } - } - - if (!step_selected && is_forward) { - WizardDone(true); - } -} - -void Wizard::SelectNextStep() { - SelectStep(true); -} - -void Wizard::SelectPreviousStep() { - SelectStep(false); -} - -void Wizard::SetImage(const std::wstring& image_name, SkBitmap* image) { - ImageMap::iterator i = images_.find(image_name); - if (i != images_.end()) - delete i->second; - images_[image_name] = image; -} - -SkBitmap* Wizard::GetImage(const std::wstring& image_name, bool remove_image) { - ImageMap::iterator i = images_.find(image_name); - SkBitmap* bitmap = NULL; - if (i != images_.end()) { - bitmap = i->second; - if (remove_image) { - images_.erase(i); - } - } - return bitmap; -} - -void Wizard::EnableNextStep(bool flag) { - view_->EnableNextButton(flag); -} - -bool Wizard::IsNextStepEnabled() const { - return view_->IsNextButtonEnabled(); -} - -void Wizard::EnablePreviousStep(bool flag) { - view_->EnablePreviousButton(flag); -} - -bool Wizard::IsPreviousStepEnabled() const { - return view_->IsPreviousButtonEnabled(); -} - diff --git a/chrome/browser/wizard/wizard.h b/chrome/browser/wizard/wizard.h deleted file mode 100644 index b4c4c5a..0000000 --- a/chrome/browser/wizard/wizard.h +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_WIZARD_WIZARD_H__ -#define CHROME_BROWSER_WIZARD_WIZARD_H__ - -#include <vector> - -#include "base/values.h" -#include "chrome/views/view.h" - -class WizardView; -class WizardStep; -class SkBitmap; - -//////////////////////////////////////////////////////////////////////////////// -// -// A WizardDelegate can receive a notification when the wizard session is done. -// -//////////////////////////////////////////////////////////////////////////////// -class WizardDelegate { - public: - // Inform the delegate that the user closed the wizard. if commit is true, - // the current wizard state contains the changes. - virtual void WizardClosed(bool commit) = 0; - - // Inform the delegate that the containing window should be resized such as - // the top level wizard view as returned by GetTopLevelView() has the provided - // width and height. - virtual void ResizeTopLevelView(int width, int height) = 0; -}; - -//////////////////////////////////////////////////////////////////////////////// -// -// Wizard is the main entry point for Chrome's wizard framework. The wizard can -// be configured with several WizardSteps. -// -// The Wizard returns a top level view that is typically integrated inside some -// constrained dialog. -// -//////////////////////////////////////////////////////////////////////////////// -class Wizard { - public: - - Wizard(WizardDelegate* delegate); - ~Wizard(); - - // Set the wizard state. The state is owned by the receiving wizard - // instance. - void SetState(DictionaryValue* state); - - // Return the wizard current wizard state. - DictionaryValue* GetState(); - - // Add a wizard step. The step is owned by the wizard. - void AddStep(WizardStep* s); - - // Return the number of step. - int GetStepCount() const; - - // Return the step at the provided index. - WizardStep* GetStepAt(int index); - - // Remove all the steps. - void RemoveAllSteps(); - - // Return the wizard top level view. - ChromeViews::View* GetTopLevelView(); - - // Start a wizard session. At this point, the top level view is expected to - // be inserted into a visible view hierarchy. - void Start(); - - // Aborts the current wizard session if it is running. The delegate is - // notified. This method does nothing if the wizard is not running. - void Abort(); - - // Specify an SkBitmap to be associated with the provided key. This is useful - // to help wizard step implementors only fetch or load an image once when it - // is on several steps. The image is owned by the wizard. - void SetImage(const std::wstring& image_name, SkBitmap* image); - - // Returns the image for the provided key or NULL if it doesn't exist. If the - // image exists and |remove_image| is true, the image will also be removed - // from the list of images maintained by the wizard and the caller will be - // given ownership of the bitmap. - SkBitmap* GetImage(const std::wstring& image_name, bool remove_image); - - // Step navigation - void SelectNextStep(); - void SelectPreviousStep(); - - // Invoked when the current step WizardNavigationDescriptor returned from - // GetNavigationDescriptor() changes. Call this method to refresh the wizard - // buttons. This method does nothing if the current WizardNavigationDescriptor - // is NULL. - void NavigationDescriptorChanged(); - - // Change whether the next step can be selected by the user. - void EnableNextStep(bool flag); - - // Checks whether the next step can be selected by the user. - bool IsNextStepEnabled() const; - - // Change whether the previous step can be selected by the user. - void EnablePreviousStep(bool flag); - - // Checks whether the previous step can be selected by the user. - bool IsPreviousStepEnabled() const; - - private: - friend class WizardView; - - // Select the step at the provided index. Note the caller is responsible for - // calling WillBecomeInvisible. We do this because we need the current step - // to finish editing before knowing which step to select next. - void SelectStepAt(int index); - - // Inform the wizard that the current session is over. This will reset the - // selected step and detach the main view from its container. - void Reset(); - - // Invoked by the WizardView in response to button pressed. - void Cancel(); - - // Internal step navigation. - void SelectStep(bool is_forward); - - // Abort the wizard if it is running. Notify the delegate - void WizardDone(bool commit); - - WizardView* view_; - - typedef std::vector<WizardStep*> WizardStepVector; - WizardStepVector steps_; - - WizardDelegate* delegate_; - - DictionaryValue* state_; - - int selected_step_; - - bool is_running_; - - typedef std::map<std::wstring, SkBitmap*> ImageMap; - ImageMap images_; - - DISALLOW_EVIL_CONSTRUCTORS(Wizard); -}; -#endif // CHROME_BROWSER_WIZARD_WIZARD_H__ - diff --git a/chrome/browser/wizard/wizard_step.h b/chrome/browser/wizard/wizard_step.h deleted file mode 100644 index de76962..0000000 --- a/chrome/browser/wizard/wizard_step.h +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_WIZARD_WIZARD_STEP_H -#define CHROME_BROWSER_WIZARD_WIZARD_STEP_H - -#include <string> -#include <vector> - -namespace ChromeViews { -class View; -} -class Wizard; - -// A navigation descriptor allows wizard steps to describe custom navigation -// buttons and offsets (how many step forward or backward). -struct WizardNavigationDescriptor { - public: - WizardNavigationDescriptor() : custom_default_button_(false), - default_offset_(0), - custom_alternate_button_(false), - alternate_offset_(0), - can_cancel_(true) { - } - - ~WizardNavigationDescriptor() {} - - // - // Default button definition. - // - - // true if the steps wants a custom default button. - bool custom_default_button_; - - // Default button label or empty string to remove the button completely. - std::wstring default_label_; - - // Positive or negative offset to the step that should become selected when - // the default button is pressed. - int default_offset_; - - // - // Alternate button definition. - // - - // true if the steps wants a custom alternate button. - bool custom_alternate_button_; - - // Alternate button label or empty string to remove the button completelty. - // This button is typically used for "previous" - std::wstring alternate_label_; - - // Positive or negative offset to the step that should become selected - // when the alternate button is pressed. - int alternate_offset_; - - // Whether the step features a cancel button. - bool can_cancel_; - - private: - - DISALLOW_EVIL_CONSTRUCTORS(WizardNavigationDescriptor); -}; - -//////////////////////////////////////////////////////////////////////////////// -// -// A WizardStep instance represents a single wizard step. -// -//////////////////////////////////////////////////////////////////////////////// -class WizardStep { - public: - enum StepAction { - DEFAULT_ACTION = 0, // Usually next - ALTERNATE_ACTION = 1, // Usually previous - CANCEL_ACTION = 2 // The cancel button has been pressed. - }; - - // Return the title for this state. If an empty string is returned, no title - // will be visible. - virtual const std::wstring GetTitle(Wizard* wizard) = 0; - - // Return the view for this state. The view is owned by the step - virtual ChromeViews::View* GetView(Wizard* wizard) = 0; - - // Return whether this step is enabled given the provided wizard state. - // If the step returns false it won't be shown in the flow. - virtual bool IsEnabledFor(Wizard* wizard) = 0; - - // Inform the step that it is now visible. The step view has been added to a - // view hierarchy. - virtual void DidBecomeVisible(Wizard* wizard) = 0; - - // Inform the step that it is about to become invisible. Any - // change pending in the UI should be flushed. |action| defines what button - // the user clicked. (see above) - virtual void WillBecomeInvisible(Wizard* wizard, StepAction action) = 0; - - // Fill lines with some human readable text describing what this step will do - // The provided strings are owned by the caller. - virtual void GetSummary(Wizard* wizard, - std::vector<std::wstring>* lines) = 0; - - // Dispose this step. This should delete the step. - virtual void Dispose() = 0; - - // Return a custom wizard navigation descriptor. This method can return NULL - // to simply use the default buttons. The returned descriptor is owned by - // the receiver and is assumed to be valid as long as the receiver is - // visible. Call Wizard::NavigationDescriptorChanged() if you need to change - // the navigation buttons while the wizard step is visible. - virtual WizardNavigationDescriptor* GetNavigationDescriptor() = 0; -}; - -#endif // CHROME_BROWSER_WIZARD_WIZARD_STEP_H - |