<commit_before>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit (ITK)
  Module:
  Language:  C++
  Date:
  Version:

Copyright (c) 2000 National Library of Medicine
All rights reserved.

See COPYRIGHT.txt for copyright details.

=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#include <iostream>
// This file has been generated by BuildHeaderTest.tcl
// Test to include each header file for Insight

#include "itkAcosImageAdaptor.h"
#include "itkAddImageAdaptor.h"
#include "itkAddPixelAccessor.h"
#include "itkAffineTransform.txx"
#include "itkArray.txx"
#include "itkArray2D.txx"
#include "itkAsinImageAdaptor.h"
#include "itkAtanImageAdaptor.h"
#include "itkAutoPointer.h"
#include "itkAzimuthElevationToCartesianTransform.txx"
#include "itkBSplineDeformableTransform.txx"
#include "itkBSplineDerivativeKernelFunction.h"
#include "itkBSplineInterpolationWeightFunction.txx"
#include "itkBSplineKernelFunction.h"
#include "itkBackwardDifferenceOperator.txx"
#include "itkBinaryBallStructuringElement.txx"
#include "itkBinaryThresholdImageFunction.txx"
#include "itkBloxBoundaryPointImage.txx"
#include "itkBloxBoundaryPointItem.txx"
#include "itkBloxBoundaryPointPixel.txx"
#include "itkBloxBoundaryProfileImage.txx"
#include "itkBloxBoundaryProfileItem.txx"
#include "itkBloxBoundaryProfilePixel.txx"
#include "itkBloxCoreAtomImage.txx"
#include "itkBloxCoreAtomItem.txx"
#include "itkBloxCoreAtomPixel.txx"
#include "itkBloxImage.txx"
#include "itkBloxItem.h"
#include "itkBloxPixel.txx"
#include "itkBluePixelAccessor.h"
#include "itkBoundingBox.txx"
#include "itkByteSwapper.txx"
#include "itkCellBoundary.txx"
#include "itkCellInterface.txx"
#include "itkCellInterfaceVisitor.h"
#include "itkCentralDifferenceImageFunction.txx"
#include "itkColorTable.txx"
#include "itkCommand.h"
#include "itkConceptChecking.h"
#include "itkConditionalConstIterator.txx"
#include "itkConditionalIterator.txx"
#include "itkConicShellInteriorExteriorSpatialFunction.txx"
#include "itkConstNeighborhoodIterator.txx"
#include "itkConstRandomAccessNeighborhoodIterator.txx"
#include "itkConstSliceIterator.h"
#include "itkConstSmartNeighborhoodIterator.txx"
#include "itkConstantBoundaryCondition.h"
#include "itkContinuousIndex.h"
#include "itkCosImageAdaptor.h"
#include "itkCovariantVector.txx"
#include "itkCreateObjectFunction.h"
#include "itkDataObject.h"
#include "itkDecisionRuleBase.h"
#include "itkDefaultDynamicMeshTraits.h"
#include "itkDefaultImageTraits.h"
#include "itkDefaultPixelAccessor.h"
#include "itkDefaultStaticMeshTraits.h"
#include "itkDenseFiniteDifferenceImageFilter.txx"
#include "itkDerivativeOperator.txx"
#include "itkDifferenceImageFilter.txx"
#include "itkDirectory.h"
#include "itkDynamicLoader.h"
#include "itkElasticBodyReciprocalSplineKernelTransform.txx"
#include "itkElasticBodySplineKernelTransform.txx"
#include "itkEllipsoidInteriorExteriorSpatialFunction.txx"
#include "itkEntropyPreservingGradientMagnitudeImageFunction.txx"
#include "itkEuler2DTransform.txx"
#include "itkEventObject.h"
#include "itkExceptionObject.h"
#include "itkExpImageAdaptor.h"
#include "itkExpNegativeImageAdaptor.h"
#include "itkFastMutexLock.h"
#include "itkFileOutputWindow.h"
#include "itkFiniteDifferenceFunction.txx"
#include "itkFiniteDifferenceImageFilter.txx"
#include "itkFixedArray.txx"
#include "itkFloodFilledFunctionConditionalConstIterator.txx"
#include "itkFloodFilledFunctionConditionalIterator.txx"
#include "itkFloodFilledImageFunctionConditionalConstIterator.txx"
#include "itkFloodFilledImageFunctionConditionalIterator.txx"
#include "itkFloodFilledSpatialFunctionConditionalConstIterator.txx"
#include "itkFloodFilledSpatialFunctionConditionalIterator.txx"
#include "itkForwardDifferenceOperator.txx"
#include "itkFrustumSpatialFunction.txx"
#include "itkFunctionBase.h"
#include "itkGaussianKernelFunction.h"
#include "itkGaussianOperator.txx"
#include "itkGaussianSpatialFunction.txx"
#include "itkGreenPixelAccessor.h"
#include "itkHexahedronCell.txx"
#include "itkHexahedronCellTopology.h"
#include "itkIdentityTransform.h"
#include "itkImage.txx"
#include "itkImageAdaptor.txx"
#include "itkImageBase.txx"
#include "itkImageBoundaryCondition.h"
#include "itkImageConstIterator.txx"
#include "itkImageConstIteratorWithIndex.txx"
#include "itkImageContainerInterface.h"
#include "itkImageFunction.txx"
#include "itkImageIO.h"
#include "itkImageIOCommon.h"
#include "itkImageIterator.txx"
#include "itkImageIteratorWithIndex.txx"
#include "itkImageLinearConstIteratorWithIndex.txx"
#include "itkImageLinearIteratorWithIndex.txx"
#include "itkImageRandomConstIteratorWithIndex.txx"
#include "itkImageRandomIteratorWithIndex.txx"
#include "itkImageRegion.txx"
#include "itkImageRegionConstIterator.txx"
#include "itkImageRegionConstIteratorWithIndex.txx"
#include "itkImageRegionExclusionConstIteratorWithIndex.txx"
#include "itkImageRegionExclusionIteratorWithIndex.txx"
#include "itkImageRegionIterator.txx"
#include "itkImageRegionIteratorWithIndex.txx"
#include "itkImageRegionMultidimensionalSplitter.txx"
#include "itkImageRegionReverseConstIterator.txx"
#include "itkImageRegionReverseIterator.txx"
#include "itkImageRegionSplitter.txx"
#include "itkImageReverseConstIterator.txx"
#include "itkImageReverseIterator.txx"
#include "itkImageSliceConstIteratorWithIndex.txx"
#include "itkImageSliceIteratorWithIndex.txx"
#include "itkImageSource.txx"
#include "itkImageToImageFilter.txx"
#include "itkImageToImageFilterDetail.h"
#include "itkImportImageContainer.txx"
#include "itkIndent.h"
#include "itkIndex.h"
#include "itkIndexedContainerInterface.h"
#include "itkIntTypes.h"
#include "itkInteriorExteriorSpatialFunction.txx"
#include "itkInterpolateImageFunction.h"
#include "itkIterationReporter.h"
#include "itkKLMSegmentationBorder.h"
#include "itkKLMSegmentationRegion.h"
#include "itkKernelFunction.h"
#include "itkKernelTransform.txx"
#include "itkLaplacianOperator.txx"
#include "itkLevelSet.h"
#include "itkLevelSetCurvatureFunction.txx"
#include "itkLevelSetFunction.txx"
#include "itkLevelSetFunctionBase.txx"
#include "itkLightObject.h"
#include "itkLightProcessObject.h"
#include "itkLineCell.txx"
#include "itkLinearInterpolateImageFunction.txx"
#include "itkLog10ImageAdaptor.h"
#include "itkLogImageAdaptor.h"
#include "itkMacro.h"
#include "itkMapContainer.txx"
#include "itkMatrix.txx"
#include "itkMaximumDecisionRule.h"
#include "itkMeanImageFunction.txx"
#include "itkMedianImageFunction.txx"
#include "itkMesh.txx"
#include "itkMeshRegion.h"
#include "itkMeshSource.txx"
#include "itkMeshToMeshFilter.txx"
#include "itkMinimumDecisionRule.h"
#include "itkMultiThreader.h"
#include "itkMutexLock.h"
#include "itkMutexLockHolder.h"
#include "itkNearestNeighborInterpolateImageFunction.h"
#include "itkNeighborhood.txx"
#include "itkNeighborhoodAlgorithm.txx"
#include "itkNeighborhoodAllocator.h"
#include "itkNeighborhoodBinaryThresholdImageFunction.txx"
#include "itkNeighborhoodInnerProduct.txx"
#include "itkNeighborhoodIterator.txx"
#include "itkNeighborhoodOperator.txx"
#include "itkNthElementImageAdaptor.h"
#include "itkNthElementPixelAccessor.h"
#include "itkNumericTraits.h"
#include "itkObject.h"
#include "itkObjectFactory.h"
#include "itkObjectFactoryBase.h"
#include "itkObjectStore.txx"
#include "itkOffset.h"
#include "itkOutputWindow.h"
#include "itkPixelAccessor.h"
#include "itkPixelTraits.h"
#include "itkPoint.txx"
#include "itkPointLocator.txx"
#include "itkPointSet.txx"
#include "itkPolygonCell.txx"
#include "itkProcessObject.h"
#include "itkProgressReporter.h"
#include "itkQuadraticEdgeCell.txx"
#include "itkQuadraticTriangleCell.txx"
#include "itkQuadraticTriangleCellTopology.h"
#include "itkQuadrilateralCell.txx"
#include "itkQuadrilateralCellTopology.h"
#include "itkQuaternionRigidTransform.txx"
#include "itkRGBAPixel.txx"
#include "itkRGBPixel.txx"
#include "itkRandomAccessNeighborhoodIterator.txx"
#include "itkRedPixelAccessor.h"
#include "itkRegion.h"
#include "itkRigid2DTransform.txx"
#include "itkRigid3DPerspectiveTransform.txx"
#include "itkRigid3DTransform.txx"
#include "itkSTLConstContainerAdaptor.h"
#include "itkSTLContainerAdaptor.h"
#include "itkScalarVector.h"
#include "itkScaleTransform.txx"
#include "itkSegmentationBorder.h"
#include "itkSegmentationLevelSetFunction.txx"
#include "itkSegmentationRegion.h"
#include "itkSimilarity2DTransform.txx"
#include "itkSimpleFastMutexLock.h"
#include "itkSinImageAdaptor.h"
#include "itkSize.h"
#include "itkSliceIterator.h"
#include "itkSmartNeighborhoodIterator.txx"
#include "itkSmartPointer.h"
#include "itkSmartPointerForwardReference.txx"
#include "itkSobelOperator.txx"
#include "itkSpatialFunction.txx"
#include "itkSphereSpatialFunction.txx"
#include "itkSqrtImageAdaptor.h"
#include "itkSymmetricEllipsoidInteriorExteriorSpatialFunction.txx"
#include "itkTanImageAdaptor.h"
#include "itkTetrahedronCell.txx"
#include "itkTetrahedronCellTopology.h"
#include "itkTextOutput.h"
#include "itkThinPlateR2LogRSplineKernelTransform.txx"
#include "itkThinPlateSplineKernelTransform.txx"
#include "itkTimeProbe.h"
#include "itkTimeProbesCollectorBase.h"
#include "itkTimeStamp.h"
#include "itkTorusInteriorExteriorSpatialFunction.txx"
#include "itkTransform.txx"
#include "itkTranslationTransform.txx"
#include "itkTriangleCell.txx"
#include "itkTriangleCellTopology.h"
#include "itkUpwindDerivativeImageFunction.txx"
#include "itkValarrayImageContainer.h"
#include "itkVarianceImageFunction.txx"
#include "itkVector.txx"
#include "itkVectorContainer.txx"
#include "itkVectorInterpolateImageFunction.h"
#include "itkVectorLinearInterpolateImageFunction.txx"
#include "itkVectorNeighborhoodInnerProduct.txx"
#include "itkVersion.h"
#include "itkVersor.txx"
#include "itkVersorRigid3DTransform.txx"
#include "itkVersorTransform.txx"
#include "itkVertexCell.txx"
#include "itkVolumeSplineKernelTransform.txx"
#include "itkWeakPointer.h"
#include "itkXMLFileOutputWindow.h"
#include "itkZeroFluxNeumannBoundaryCondition.txx"
#include "itk_alloc.h"
#include "itk_hash_map.h"
#include "itk_hash_set.h"
#include "itk_hashtable.h"
#include "vcl_alloc.h"

int main ( int , char*  )
{

  return 0;
}

<commit_msg>ENH: Updated to latest headers<commit_after>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit (ITK)
  Module:
  Language:  C++
  Date:
  Version:

Copyright (c) 2000 National Library of Medicine
All rights reserved.

See COPYRIGHT.txt for copyright details.

=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#include <iostream>
// This file has been generated by BuildHeaderTest.tcl
// Test to include each header file for Insight

#include "itkAcosImageAdaptor.h"
#include "itkAddImageAdaptor.h"
#include "itkAddPixelAccessor.h"
#include "itkAffineTransform.txx"
#include "itkArray.txx"
#include "itkArray2D.txx"
#include "itkAsinImageAdaptor.h"
#include "itkAtanImageAdaptor.h"
#include "itkAutoPointer.h"
#include "itkAzimuthElevationToCartesianTransform.txx"
#include "itkBSplineDeformableTransform.txx"
#include "itkBSplineDerivativeKernelFunction.h"
#include "itkBSplineInterpolationWeightFunction.txx"
#include "itkBSplineKernelFunction.h"
#include "itkBackwardDifferenceOperator.txx"
#include "itkBinaryBallStructuringElement.txx"
#include "itkBinaryThresholdImageFunction.txx"
#include "itkBloxBoundaryPointImage.txx"
#include "itkBloxBoundaryPointItem.txx"
#include "itkBloxBoundaryPointPixel.txx"
#include "itkBloxBoundaryProfileImage.txx"
#include "itkBloxBoundaryProfileItem.txx"
#include "itkBloxBoundaryProfilePixel.txx"
#include "itkBloxCoreAtomImage.txx"
#include "itkBloxCoreAtomItem.txx"
#include "itkBloxCoreAtomPixel.txx"
#include "itkBloxImage.txx"
#include "itkBloxItem.h"
#include "itkBloxPixel.txx"
#include "itkBluePixelAccessor.h"
#include "itkBoundingBox.txx"
#include "itkByteSwapper.txx"
#include "itkCellBoundary.txx"
#include "itkCellInterface.txx"
#include "itkCellInterfaceVisitor.h"
#include "itkCentralDifferenceImageFunction.txx"
#include "itkColorTable.txx"
#include "itkCommand.h"
#include "itkConceptChecking.h"
#include "itkConditionalConstIterator.txx"
#include "itkConditionalIterator.txx"
#include "itkConicShellInteriorExteriorSpatialFunction.txx"
#include "itkConstNeighborhoodIterator.txx"
#include "itkConstRandomAccessNeighborhoodIterator.txx"
#include "itkConstShapedNeighborhoodIterator.txx"
#include "itkConstSliceIterator.h"
#include "itkConstSmartNeighborhoodIterator.txx"
#include "itkConstantBoundaryCondition.h"
#include "itkContinuousIndex.h"
#include "itkCosImageAdaptor.h"
#include "itkCovariantVector.txx"
#include "itkCreateObjectFunction.h"
#include "itkDataObject.h"
#include "itkDecisionRuleBase.h"
#include "itkDefaultDynamicMeshTraits.h"
#include "itkDefaultImageTraits.h"
#include "itkDefaultPixelAccessor.h"
#include "itkDefaultStaticMeshTraits.h"
#include "itkDenseFiniteDifferenceImageFilter.txx"
#include "itkDerivativeOperator.txx"
#include "itkDifferenceImageFilter.txx"
#include "itkDirectory.h"
#include "itkDynamicLoader.h"
#include "itkElasticBodyReciprocalSplineKernelTransform.txx"
#include "itkElasticBodySplineKernelTransform.txx"
#include "itkEllipsoidInteriorExteriorSpatialFunction.txx"
#include "itkEntropyPreservingGradientMagnitudeImageFunction.txx"
#include "itkEuler2DTransform.txx"
#include "itkEventObject.h"
#include "itkExceptionObject.h"
#include "itkExpImageAdaptor.h"
#include "itkExpNegativeImageAdaptor.h"
#include "itkFastMutexLock.h"
#include "itkFileOutputWindow.h"
#include "itkFiniteDifferenceFunction.txx"
#include "itkFiniteDifferenceImageFilter.txx"
#include "itkFixedArray.txx"
#include "itkFloodFilledFunctionConditionalConstIterator.txx"
#include "itkFloodFilledFunctionConditionalIterator.txx"
#include "itkFloodFilledImageFunctionConditionalConstIterator.txx"
#include "itkFloodFilledImageFunctionConditionalIterator.txx"
#include "itkFloodFilledSpatialFunctionConditionalConstIterator.txx"
#include "itkFloodFilledSpatialFunctionConditionalIterator.txx"
#include "itkForwardDifferenceOperator.txx"
#include "itkFrustumSpatialFunction.txx"
#include "itkFunctionBase.h"
#include "itkGaussianKernelFunction.h"
#include "itkGaussianOperator.txx"
#include "itkGaussianSpatialFunction.txx"
#include "itkGreenPixelAccessor.h"
#include "itkHexahedronCell.txx"
#include "itkHexahedronCellTopology.h"
#include "itkIdentityTransform.h"
#include "itkImage.txx"
#include "itkImageAdaptor.txx"
#include "itkImageBase.txx"
#include "itkImageBoundaryCondition.h"
#include "itkImageConstIterator.txx"
#include "itkImageConstIteratorWithIndex.txx"
#include "itkImageContainerInterface.h"
#include "itkImageFunction.txx"
#include "itkImageIO.h"
#include "itkImageIOCommon.h"
#include "itkImageIterator.txx"
#include "itkImageIteratorWithIndex.txx"
#include "itkImageLinearConstIteratorWithIndex.txx"
#include "itkImageLinearIteratorWithIndex.txx"
#include "itkImageRandomConstIteratorWithIndex.txx"
#include "itkImageRandomIteratorWithIndex.txx"
#include "itkImageRegion.txx"
#include "itkImageRegionConstIterator.txx"
#include "itkImageRegionConstIteratorWithIndex.txx"
#include "itkImageRegionExclusionConstIteratorWithIndex.txx"
#include "itkImageRegionExclusionIteratorWithIndex.txx"
#include "itkImageRegionIterator.txx"
#include "itkImageRegionIteratorWithIndex.txx"
#include "itkImageRegionMultidimensionalSplitter.txx"
#include "itkImageRegionReverseConstIterator.txx"
#include "itkImageRegionReverseIterator.txx"
#include "itkImageRegionSplitter.txx"
#include "itkImageReverseConstIterator.txx"
#include "itkImageReverseIterator.txx"
#include "itkImageSliceConstIteratorWithIndex.txx"
#include "itkImageSliceIteratorWithIndex.txx"
#include "itkImageSource.txx"
#include "itkImageToImageFilter.txx"
#include "itkImageToImageFilterDetail.h"
#include "itkImportImageContainer.txx"
#include "itkIndent.h"
#include "itkIndex.h"
#include "itkIndexedContainerInterface.h"
#include "itkIntTypes.h"
#include "itkInteriorExteriorSpatialFunction.txx"
#include "itkInterpolateImageFunction.h"
#include "itkIterationReporter.h"
#include "itkKLMSegmentationBorder.h"
#include "itkKLMSegmentationRegion.h"
#include "itkKernelFunction.h"
#include "itkKernelTransform.txx"
#include "itkLaplacianOperator.txx"
#include "itkLevelSet.h"
#include "itkLevelSetCurvatureFunction.txx"
#include "itkLevelSetFunction.txx"
#include "itkLevelSetFunctionBase.txx"
#include "itkLightObject.h"
#include "itkLightProcessObject.h"
#include "itkLineCell.txx"
#include "itkLinearInterpolateImageFunction.txx"
#include "itkLog10ImageAdaptor.h"
#include "itkLogImageAdaptor.h"
#include "itkMacro.h"
#include "itkMapContainer.txx"
#include "itkMatrix.txx"
#include "itkMaximumDecisionRule.h"
#include "itkMeanImageFunction.txx"
#include "itkMedianImageFunction.txx"
#include "itkMesh.txx"
#include "itkMeshRegion.h"
#include "itkMeshSource.txx"
#include "itkMeshToMeshFilter.txx"
#include "itkMinimumDecisionRule.h"
#include "itkMultiThreader.h"
#include "itkMutexLock.h"
#include "itkMutexLockHolder.h"
#include "itkNearestNeighborInterpolateImageFunction.h"
#include "itkNeighborhood.txx"
#include "itkNeighborhoodAlgorithm.txx"
#include "itkNeighborhoodAllocator.h"
#include "itkNeighborhoodBinaryThresholdImageFunction.txx"
#include "itkNeighborhoodInnerProduct.txx"
#include "itkNeighborhoodIterator.txx"
#include "itkNeighborhoodOperator.txx"
#include "itkNthElementImageAdaptor.h"
#include "itkNthElementPixelAccessor.h"
#include "itkNumericTraits.h"
#include "itkObject.h"
#include "itkObjectFactory.h"
#include "itkObjectFactoryBase.h"
#include "itkObjectStore.txx"
#include "itkOffset.h"
#include "itkOutputWindow.h"
#include "itkPixelAccessor.h"
#include "itkPixelTraits.h"
#include "itkPoint.txx"
#include "itkPointLocator.txx"
#include "itkPointSet.txx"
#include "itkPolygonCell.txx"
#include "itkProcessObject.h"
#include "itkProgressReporter.h"
#include "itkQuadraticEdgeCell.txx"
#include "itkQuadraticTriangleCell.txx"
#include "itkQuadraticTriangleCellTopology.h"
#include "itkQuadrilateralCell.txx"
#include "itkQuadrilateralCellTopology.h"
#include "itkQuaternionRigidTransform.txx"
#include "itkRGBAPixel.txx"
#include "itkRGBPixel.txx"
#include "itkRandomAccessNeighborhoodIterator.txx"
#include "itkRedPixelAccessor.h"
#include "itkRegion.h"
#include "itkRigid2DTransform.txx"
#include "itkRigid3DPerspectiveTransform.txx"
#include "itkRigid3DTransform.txx"
#include "itkSTLConstContainerAdaptor.h"
#include "itkSTLContainerAdaptor.h"
#include "itkScalarVector.h"
#include "itkScaleTransform.txx"
#include "itkSegmentationBorder.h"
#include "itkSegmentationLevelSetFunction.txx"
#include "itkSegmentationRegion.h"
#include "itkShapedNeighborhoodIterator.txx"
#include "itkSimilarity2DTransform.txx"
#include "itkSimpleFastMutexLock.h"
#include "itkSinImageAdaptor.h"
#include "itkSize.h"
#include "itkSliceIterator.h"
#include "itkSmartNeighborhoodIterator.txx"
#include "itkSmartPointer.h"
#include "itkSmartPointerForwardReference.txx"
#include "itkSobelOperator.txx"
#include "itkSpatialFunction.txx"
#include "itkSphereSpatialFunction.txx"
#include "itkSqrtImageAdaptor.h"
#include "itkSymmetricEllipsoidInteriorExteriorSpatialFunction.txx"
#include "itkTanImageAdaptor.h"
#include "itkTetrahedronCell.txx"
#include "itkTetrahedronCellTopology.h"
#include "itkTextOutput.h"
#include "itkThinPlateR2LogRSplineKernelTransform.txx"
#include "itkThinPlateSplineKernelTransform.txx"
#include "itkTimeProbe.h"
#include "itkTimeProbesCollectorBase.h"
#include "itkTimeStamp.h"
#include "itkTorusInteriorExteriorSpatialFunction.txx"
#include "itkTransform.txx"
#include "itkTranslationTransform.txx"
#include "itkTriangleCell.txx"
#include "itkTriangleCellTopology.h"
#include "itkUpwindDerivativeImageFunction.txx"
#include "itkValarrayImageContainer.h"
#include "itkVarianceImageFunction.txx"
#include "itkVector.txx"
#include "itkVectorContainer.txx"
#include "itkVectorInterpolateImageFunction.h"
#include "itkVectorLinearInterpolateImageFunction.txx"
#include "itkVectorNeighborhoodInnerProduct.txx"
#include "itkVersion.h"
#include "itkVersor.txx"
#include "itkVersorRigid3DTransform.txx"
#include "itkVersorTransform.txx"
#include "itkVertexCell.txx"
#include "itkVolumeSplineKernelTransform.txx"
#include "itkWeakPointer.h"
#include "itkXMLFileOutputWindow.h"
#include "itkZeroFluxNeumannBoundaryCondition.txx"
#include "itk_alloc.h"
#include "itk_hash_map.h"
#include "itk_hash_set.h"
#include "itk_hashtable.h"
#include "vcl_alloc.h"

int main ( int , char*  )
{

  return 0;
}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: indexentrysupplier.cxx,v $
 *
 *  $Revision: 1.19 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 09:18:13 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_i18npool.hxx"
#include <rtl/ustrbuf.hxx>
#include <indexentrysupplier.hxx>
#include <localedata.hxx>

using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::rtl;

static const sal_Unicode under = sal_Unicode('_');

namespace com { namespace sun { namespace star { namespace i18n {

IndexEntrySupplier::IndexEntrySupplier( const Reference < XMultiServiceFactory >& rxMSF ) : xMSF( rxMSF )
{
}

Sequence < Locale > SAL_CALL IndexEntrySupplier::getLocaleList() throw (RuntimeException)
{
        return LocaleData().getAllInstalledLocaleNames();
}

Sequence < OUString > SAL_CALL IndexEntrySupplier::getAlgorithmList( const Locale& rLocale ) throw (RuntimeException)
{
        return LocaleData().getIndexAlgorithm(rLocale);
}

sal_Bool SAL_CALL IndexEntrySupplier::loadAlgorithm( const Locale& rLocale, const OUString& SortAlgorithm,
        sal_Int32 collatorOptions ) throw (RuntimeException)
{
        Sequence < OUString > algorithmList = getAlgorithmList( rLocale );
        for (sal_Int32 i = 0; i < algorithmList.getLength(); i++) {
            if (algorithmList[i] == SortAlgorithm) {
                if (getLocaleSpecificIndexEntrySupplier(rLocale, SortAlgorithm).is())
                    return xIES->loadAlgorithm(rLocale, SortAlgorithm, collatorOptions);
            }
        }
        return sal_False;
}

sal_Bool SAL_CALL IndexEntrySupplier::usePhoneticEntry( const Locale& rLocale ) throw (RuntimeException)
{
        return LocaleData().hasPhonetic(rLocale);
}

OUString SAL_CALL IndexEntrySupplier::getPhoneticCandidate( const OUString& rIndexEntry,
        const Locale& rLocale ) throw (RuntimeException)
{
        if (getLocaleSpecificIndexEntrySupplier(rLocale, OUString()).is())
            return xIES->getPhoneticCandidate(rIndexEntry, rLocale);
        else
            throw RuntimeException();
}

OUString SAL_CALL IndexEntrySupplier::getIndexKey( const OUString& rIndexEntry,
        const OUString& rPhoneticEntry, const Locale& rLocale ) throw (RuntimeException)
{
        if (xIES.is())
            return xIES->getIndexKey(rIndexEntry, rPhoneticEntry, rLocale);
        else
            throw RuntimeException();
}

sal_Int16 SAL_CALL IndexEntrySupplier::compareIndexEntry(
        const OUString& rIndexEntry1, const OUString& rPhoneticEntry1, const Locale& rLocale1,
        const OUString& rIndexEntry2, const OUString& rPhoneticEntry2, const Locale& rLocale2 )
        throw (com::sun::star::uno::RuntimeException)
{
        if (xIES.is())
            return xIES->compareIndexEntry(rIndexEntry1, rPhoneticEntry1, rLocale1,
                                        rIndexEntry2, rPhoneticEntry2, rLocale2);
        else
            throw RuntimeException();
}

OUString SAL_CALL IndexEntrySupplier::getIndexCharacter( const OUString& rIndexEntry,
        const Locale& rLocale, const OUString& rSortAlgorithm )
        throw (RuntimeException)
{
        return getLocaleSpecificIndexEntrySupplier(rLocale, rSortAlgorithm)->
                        getIndexCharacter( rIndexEntry, rLocale, rSortAlgorithm );
}

sal_Bool SAL_CALL IndexEntrySupplier::createLocaleSpecificIndexEntrySupplier(const OUString& name) throw( RuntimeException )
{
        Reference < XInterface > xI = xMSF->createInstance(
            OUString::createFromAscii("com.sun.star.i18n.IndexEntrySupplier_") + name);

        if ( xI.is() ) {
            xI->queryInterface( ::getCppuType((const Reference< com::sun::star::i18n::XExtendedIndexEntrySupplier>*)0) ) >>= xIES;
            return xIES.is();
        }
        return sal_False;
}

Reference < com::sun::star::i18n::XExtendedIndexEntrySupplier > SAL_CALL
IndexEntrySupplier::getLocaleSpecificIndexEntrySupplier(const Locale& rLocale, const OUString& rSortAlgorithm) throw (RuntimeException)
{
        if (xIES.is() && rSortAlgorithm == aSortAlgorithm && rLocale.Language == aLocale.Language &&
                rLocale.Country == aLocale.Country && rLocale.Variant == aLocale.Variant)
            return xIES;
        else if (xMSF.is()) {
            LocaleData ld;
            aLocale = rLocale;
            if (rSortAlgorithm.getLength() == 0)
                aSortAlgorithm = ld.getDefaultIndexAlgorithm( rLocale );
            else
                aSortAlgorithm = rSortAlgorithm;

            OUString module = ld.getIndexModuleByAlgorithm(rLocale, aSortAlgorithm);
            if (module.getLength() > 0 && createLocaleSpecificIndexEntrySupplier(module))
                return xIES;

            sal_Int32 l = rLocale.Language.getLength();
            sal_Int32 c = rLocale.Country.getLength();
            sal_Int32 v = rLocale.Variant.getLength();
            sal_Int32 a = aSortAlgorithm.getLength();
            OUStringBuffer aBuf(l+c+v+a+4);

            if ((l > 0 && c > 0 && v > 0 && a > 0 &&
                        // load service with name <base>_<lang>_<country>_<varian>_<algorithm>
                        createLocaleSpecificIndexEntrySupplier(aBuf.append(rLocale.Language).append(under).append(
                                    rLocale.Country).append(under).append(rLocale.Variant).append(under).append(
                                    aSortAlgorithm).makeStringAndClear())) ||
                (l > 0 && c > 0 && a > 0 &&
                        // load service with name <base>_<lang>_<country>_<algorithm>
                        createLocaleSpecificIndexEntrySupplier(aBuf.append(rLocale.Language).append(under).append(
                                    rLocale.Country).append(under).append(aSortAlgorithm).makeStringAndClear())) ||
                (l > 0 && c > 0 && a > 0 && rLocale.Language.compareToAscii("zh") == 0 &&
                                            (rLocale.Country.compareToAscii("HK") == 0 ||
                                            rLocale.Country.compareToAscii("MO") == 0) &&
                        // if the country code is HK or MO, one more step to try TW.
                        createLocaleSpecificIndexEntrySupplier(aBuf.append(rLocale.Language).append(under).appendAscii(
                                    "TW").append(under).append(aSortAlgorithm).makeStringAndClear())) ||
                (l > 0 && a > 0 &&
                        // load service with name <base>_<lang>_<algorithm>
                        createLocaleSpecificIndexEntrySupplier(aBuf.append(rLocale.Language).append(under).append(
                                    aSortAlgorithm).makeStringAndClear())) ||
                        // load service with name <base>_<algorithm>
                (a > 0 && createLocaleSpecificIndexEntrySupplier(aSortAlgorithm)) ||
                        // load default service with name <base>_Unicode
                        createLocaleSpecificIndexEntrySupplier(OUString::createFromAscii("Unicode"))) {
                return xIES;
            }
        }
        throw RuntimeException();
}

OUString SAL_CALL IndexEntrySupplier::getIndexFollowPageWord( sal_Bool bMorePages,
        const Locale& rLocale ) throw (RuntimeException)
{
        Sequence< OUString > aFollowPageWords = LocaleData().getFollowPageWords(rLocale);

        return (bMorePages && aFollowPageWords.getLength() > 1) ?
            aFollowPageWords[1] : (aFollowPageWords.getLength() > 0 ?
            aFollowPageWords[0] : OUString());
}

#define implementationName "com.sun.star.i18n.IndexEntrySupplier"

OUString SAL_CALL
IndexEntrySupplier::getImplementationName() throw( RuntimeException )
{
        return OUString::createFromAscii( implementationName );
}

sal_Bool SAL_CALL
IndexEntrySupplier::supportsService(const OUString& rServiceName) throw( RuntimeException )
{
        return rServiceName.compareToAscii(implementationName) == 0;
}

Sequence< OUString > SAL_CALL
IndexEntrySupplier::getSupportedServiceNames() throw( RuntimeException )
{
        Sequence< OUString > aRet(1);
        aRet[0] = OUString::createFromAscii( implementationName );
        return aRet;
}

} } } }
<commit_msg>INTEGRATION: CWS changefileheader (1.19.138); FILE MERGED 2008/03/31 16:01:22 rt 1.19.138.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: indexentrysupplier.cxx,v $
 * $Revision: 1.20 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_i18npool.hxx"
#include <rtl/ustrbuf.hxx>
#include <indexentrysupplier.hxx>
#include <localedata.hxx>

using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::rtl;

static const sal_Unicode under = sal_Unicode('_');

namespace com { namespace sun { namespace star { namespace i18n {

IndexEntrySupplier::IndexEntrySupplier( const Reference < XMultiServiceFactory >& rxMSF ) : xMSF( rxMSF )
{
}

Sequence < Locale > SAL_CALL IndexEntrySupplier::getLocaleList() throw (RuntimeException)
{
        return LocaleData().getAllInstalledLocaleNames();
}

Sequence < OUString > SAL_CALL IndexEntrySupplier::getAlgorithmList( const Locale& rLocale ) throw (RuntimeException)
{
        return LocaleData().getIndexAlgorithm(rLocale);
}

sal_Bool SAL_CALL IndexEntrySupplier::loadAlgorithm( const Locale& rLocale, const OUString& SortAlgorithm,
        sal_Int32 collatorOptions ) throw (RuntimeException)
{
        Sequence < OUString > algorithmList = getAlgorithmList( rLocale );
        for (sal_Int32 i = 0; i < algorithmList.getLength(); i++) {
            if (algorithmList[i] == SortAlgorithm) {
                if (getLocaleSpecificIndexEntrySupplier(rLocale, SortAlgorithm).is())
                    return xIES->loadAlgorithm(rLocale, SortAlgorithm, collatorOptions);
            }
        }
        return sal_False;
}

sal_Bool SAL_CALL IndexEntrySupplier::usePhoneticEntry( const Locale& rLocale ) throw (RuntimeException)
{
        return LocaleData().hasPhonetic(rLocale);
}

OUString SAL_CALL IndexEntrySupplier::getPhoneticCandidate( const OUString& rIndexEntry,
        const Locale& rLocale ) throw (RuntimeException)
{
        if (getLocaleSpecificIndexEntrySupplier(rLocale, OUString()).is())
            return xIES->getPhoneticCandidate(rIndexEntry, rLocale);
        else
            throw RuntimeException();
}

OUString SAL_CALL IndexEntrySupplier::getIndexKey( const OUString& rIndexEntry,
        const OUString& rPhoneticEntry, const Locale& rLocale ) throw (RuntimeException)
{
        if (xIES.is())
            return xIES->getIndexKey(rIndexEntry, rPhoneticEntry, rLocale);
        else
            throw RuntimeException();
}

sal_Int16 SAL_CALL IndexEntrySupplier::compareIndexEntry(
        const OUString& rIndexEntry1, const OUString& rPhoneticEntry1, const Locale& rLocale1,
        const OUString& rIndexEntry2, const OUString& rPhoneticEntry2, const Locale& rLocale2 )
        throw (com::sun::star::uno::RuntimeException)
{
        if (xIES.is())
            return xIES->compareIndexEntry(rIndexEntry1, rPhoneticEntry1, rLocale1,
                                        rIndexEntry2, rPhoneticEntry2, rLocale2);
        else
            throw RuntimeException();
}

OUString SAL_CALL IndexEntrySupplier::getIndexCharacter( const OUString& rIndexEntry,
        const Locale& rLocale, const OUString& rSortAlgorithm )
        throw (RuntimeException)
{
        return getLocaleSpecificIndexEntrySupplier(rLocale, rSortAlgorithm)->
                        getIndexCharacter( rIndexEntry, rLocale, rSortAlgorithm );
}

sal_Bool SAL_CALL IndexEntrySupplier::createLocaleSpecificIndexEntrySupplier(const OUString& name) throw( RuntimeException )
{
        Reference < XInterface > xI = xMSF->createInstance(
            OUString::createFromAscii("com.sun.star.i18n.IndexEntrySupplier_") + name);

        if ( xI.is() ) {
            xI->queryInterface( ::getCppuType((const Reference< com::sun::star::i18n::XExtendedIndexEntrySupplier>*)0) ) >>= xIES;
            return xIES.is();
        }
        return sal_False;
}

Reference < com::sun::star::i18n::XExtendedIndexEntrySupplier > SAL_CALL
IndexEntrySupplier::getLocaleSpecificIndexEntrySupplier(const Locale& rLocale, const OUString& rSortAlgorithm) throw (RuntimeException)
{
        if (xIES.is() && rSortAlgorithm == aSortAlgorithm && rLocale.Language == aLocale.Language &&
                rLocale.Country == aLocale.Country && rLocale.Variant == aLocale.Variant)
            return xIES;
        else if (xMSF.is()) {
            LocaleData ld;
            aLocale = rLocale;
            if (rSortAlgorithm.getLength() == 0)
                aSortAlgorithm = ld.getDefaultIndexAlgorithm( rLocale );
            else
                aSortAlgorithm = rSortAlgorithm;

            OUString module = ld.getIndexModuleByAlgorithm(rLocale, aSortAlgorithm);
            if (module.getLength() > 0 && createLocaleSpecificIndexEntrySupplier(module))
                return xIES;

            sal_Int32 l = rLocale.Language.getLength();
            sal_Int32 c = rLocale.Country.getLength();
            sal_Int32 v = rLocale.Variant.getLength();
            sal_Int32 a = aSortAlgorithm.getLength();
            OUStringBuffer aBuf(l+c+v+a+4);

            if ((l > 0 && c > 0 && v > 0 && a > 0 &&
                        // load service with name <base>_<lang>_<country>_<varian>_<algorithm>
                        createLocaleSpecificIndexEntrySupplier(aBuf.append(rLocale.Language).append(under).append(
                                    rLocale.Country).append(under).append(rLocale.Variant).append(under).append(
                                    aSortAlgorithm).makeStringAndClear())) ||
                (l > 0 && c > 0 && a > 0 &&
                        // load service with name <base>_<lang>_<country>_<algorithm>
                        createLocaleSpecificIndexEntrySupplier(aBuf.append(rLocale.Language).append(under).append(
                                    rLocale.Country).append(under).append(aSortAlgorithm).makeStringAndClear())) ||
                (l > 0 && c > 0 && a > 0 && rLocale.Language.compareToAscii("zh") == 0 &&
                                            (rLocale.Country.compareToAscii("HK") == 0 ||
                                            rLocale.Country.compareToAscii("MO") == 0) &&
                        // if the country code is HK or MO, one more step to try TW.
                        createLocaleSpecificIndexEntrySupplier(aBuf.append(rLocale.Language).append(under).appendAscii(
                                    "TW").append(under).append(aSortAlgorithm).makeStringAndClear())) ||
                (l > 0 && a > 0 &&
                        // load service with name <base>_<lang>_<algorithm>
                        createLocaleSpecificIndexEntrySupplier(aBuf.append(rLocale.Language).append(under).append(
                                    aSortAlgorithm).makeStringAndClear())) ||
                        // load service with name <base>_<algorithm>
                (a > 0 && createLocaleSpecificIndexEntrySupplier(aSortAlgorithm)) ||
                        // load default service with name <base>_Unicode
                        createLocaleSpecificIndexEntrySupplier(OUString::createFromAscii("Unicode"))) {
                return xIES;
            }
        }
        throw RuntimeException();
}

OUString SAL_CALL IndexEntrySupplier::getIndexFollowPageWord( sal_Bool bMorePages,
        const Locale& rLocale ) throw (RuntimeException)
{
        Sequence< OUString > aFollowPageWords = LocaleData().getFollowPageWords(rLocale);

        return (bMorePages && aFollowPageWords.getLength() > 1) ?
            aFollowPageWords[1] : (aFollowPageWords.getLength() > 0 ?
            aFollowPageWords[0] : OUString());
}

#define implementationName "com.sun.star.i18n.IndexEntrySupplier"

OUString SAL_CALL
IndexEntrySupplier::getImplementationName() throw( RuntimeException )
{
        return OUString::createFromAscii( implementationName );
}

sal_Bool SAL_CALL
IndexEntrySupplier::supportsService(const OUString& rServiceName) throw( RuntimeException )
{
        return rServiceName.compareToAscii(implementationName) == 0;
}

Sequence< OUString > SAL_CALL
IndexEntrySupplier::getSupportedServiceNames() throw( RuntimeException )
{
        Sequence< OUString > aRet(1);
        aRet[0] = OUString::createFromAscii( implementationName );
        return aRet;
}

} } } }
<|endoftext|>


<commit_before>/****************************************************************************

This file is part of the QtMediaHub project on http://www.qtmediahub.com

Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).*
All rights reserved.

Contact:  Girish Ramakrishnan girish@forwardbias.in
Contact:  Nokia Corporation donald.carr@nokia.com
Contact:  Nokia Corporation johannes.zellner@nokia.com

You may use this file under the terms of the BSD license as follows:

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Nokia Corporation and its Subsidiary(-ies) nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

****************************************************************************/

#include <QApplication>
#include <QNetworkProxy>
#include <QNetworkConfigurationManager>
#include <QNetworkSession>
#include "qtsingleapplication.h"

#include "mainwindow.h"
#include "mediaserver.h"
#include "qmh-config.h"

static QNetworkSession *g_networkSession = 0;

static void setupNetwork()
{
    QNetworkProxy proxy;
    if (Config::isEnabled("proxy", false)) {
        QString proxyHost(Config::value("proxy-host", "localhost").toString());
        int proxyPort = Config::value("proxy-port", 8080);
        proxy.setType(QNetworkProxy::HttpProxy);
        proxy.setHostName(proxyHost);
        proxy.setPort(proxyPort);
        QNetworkProxy::setApplicationProxy(proxy);
        qWarning() << "Using proxy host" << proxyHost << "on port" << proxyPort;
    }

    // Set Internet Access Point
    QNetworkConfigurationManager mgr;
    QList<QNetworkConfiguration> activeConfigs = mgr.allConfigurations();
    if (activeConfigs.count() <= 0)
        return;

    QNetworkConfiguration cfg = activeConfigs.at(0);
    foreach(QNetworkConfiguration config, activeConfigs) {
        if (config.type() == QNetworkConfiguration::UserChoice) {
            cfg = config;
            break;
        }
    }

    g_networkSession = new QNetworkSession(cfg);
    g_networkSession->open();
    g_networkSession->waitForOpened(-1);
}

int main(int argc, char** argv)
{
    QApplication::setGraphicsSystem("raster");

    QtSingleApplication app(argc, argv);
    app.setApplicationName("qtmediahub");
    app.setOrganizationName("MediaTrolls");
    app.setOrganizationDomain("qtmediahub.com");

    setupNetwork();

    bool primarySession = !app.isRunning();
    if (!(Config::isEnabled("multi-instance", false) || primarySession)) {
        qWarning() << app.applicationName() << "is already running, aborting";
        return false;
    }

    Config::init(argc, argv);

    MainWindow *mainWindow = 0;
    MediaServer *mediaServer = 0;

    if (!Config::isEnabled("headless", false)) {
        mainWindow = new MainWindow;
        mainWindow->setSkin(Config::value("skin", "").toString());
        mainWindow->show();
    } else {
        mediaServer = new MediaServer;
    }

    int ret = app.exec();

    g_networkSession->close();

    delete mainWindow;
    delete mediaServer;

    return ret;
}
<commit_msg>Don't set raster when user has explicitly set a graphics system<commit_after>/****************************************************************************

This file is part of the QtMediaHub project on http://www.qtmediahub.com

Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).*
All rights reserved.

Contact:  Girish Ramakrishnan girish@forwardbias.in
Contact:  Nokia Corporation donald.carr@nokia.com
Contact:  Nokia Corporation johannes.zellner@nokia.com

You may use this file under the terms of the BSD license as follows:

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Nokia Corporation and its Subsidiary(-ies) nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

****************************************************************************/

#include <QApplication>
#include <QNetworkProxy>
#include <QNetworkConfigurationManager>
#include <QNetworkSession>
#include "qtsingleapplication.h"

#include "mainwindow.h"
#include "mediaserver.h"
#include "qmh-config.h"

static QNetworkSession *g_networkSession = 0;

static void setupNetwork()
{
    QNetworkProxy proxy;
    if (Config::isEnabled("proxy", false)) {
        QString proxyHost(Config::value("proxy-host", "localhost").toString());
        int proxyPort = Config::value("proxy-port", 8080);
        proxy.setType(QNetworkProxy::HttpProxy);
        proxy.setHostName(proxyHost);
        proxy.setPort(proxyPort);
        QNetworkProxy::setApplicationProxy(proxy);
        qWarning() << "Using proxy host" << proxyHost << "on port" << proxyPort;
    }

    // Set Internet Access Point
    QNetworkConfigurationManager mgr;
    QList<QNetworkConfiguration> activeConfigs = mgr.allConfigurations();
    if (activeConfigs.count() <= 0)
        return;

    QNetworkConfiguration cfg = activeConfigs.at(0);
    foreach(QNetworkConfiguration config, activeConfigs) {
        if (config.type() == QNetworkConfiguration::UserChoice) {
            cfg = config;
            break;
        }
    }

    g_networkSession = new QNetworkSession(cfg);
    g_networkSession->open();
    g_networkSession->waitForOpened(-1);
}

int main(int argc, char** argv)
{
    bool overrideGraphicsSystem = false;
    for(int i = 0; i < argc; ++i) {
        if (qstrcmp(argv[i], "-graphicssystem") == 0) {
            overrideGraphicsSystem = true;
            break;
        }
    }

    if (!overrideGraphicsSystem)
        QApplication::setGraphicsSystem("raster");

    QtSingleApplication app(argc, argv);
    app.setApplicationName("qtmediahub");
    app.setOrganizationName("MediaTrolls");
    app.setOrganizationDomain("qtmediahub.com");

    setupNetwork();

    bool primarySession = !app.isRunning();
    if (!(Config::isEnabled("multi-instance", false) || primarySession)) {
        qWarning() << app.applicationName() << "is already running, aborting";
        return false;
    }

    Config::init(argc, argv);

    MainWindow *mainWindow = 0;
    MediaServer *mediaServer = 0;

    if (!Config::isEnabled("headless", false)) {
        mainWindow = new MainWindow;
        mainWindow->setSkin(Config::value("skin", "").toString());
        mainWindow->show();
    } else {
        mediaServer = new MediaServer;
    }

    int ret = app.exec();

    g_networkSession->close();

    delete mainWindow;
    delete mediaServer;

    return ret;
}
<|endoftext|>


<commit_before>// Copyright (c) 2010 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/chromeos/views/domui_menu_widget.h"

#include "chrome/browser/chromeos/views/menu_locator.h"
#include "chrome/browser/chromeos/views/native_menu_domui.h"
#include "chrome/browser/chromeos/wm_ipc.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_widget_host_view.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/views/dom_view.h"
#include "cros/chromeos_wm_ipc_enums.h"
#include "gfx/canvas_skia.h"
#include "googleurl/src/gurl.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "views/border.h"
#include "views/layout_manager.h"
#include "views/widget/root_view.h"

namespace {

// Colors for menu's graident background.
const SkColor kMenuStartColor = SK_ColorWHITE;
const SkColor kMenuEndColor = 0xFFEEEEEE;

// Rounded border for menu. This draws three types of rounded border,
// for context menu, dropdown menu and submenu. Please see
// menu_locator.cc for details.
class RoundedBorder : public views::Border {
 public:
  explicit RoundedBorder(chromeos::MenuLocator* locator)
      : menu_locator_(locator) {
  }

 private:
  // views::Border implementatios.
  virtual void Paint(const views::View& view, gfx::Canvas* canvas) const {
    const SkScalar* corners = menu_locator_->GetCorners();
    // The menu is in off screen so no need to draw corners.
    if (!corners)
      return;
    int w = view.width();
    int h = view.height();
    SkRect rect = {0, 0, w, h};
    SkPath path;
    path.addRoundRect(rect, corners);
    SkPaint paint;
    paint.setStyle(SkPaint::kFill_Style);
    paint.setFlags(SkPaint::kAntiAlias_Flag);
    SkPoint p[2] = { {0, 0}, {0, h} };
    SkColor colors[2] = {kMenuStartColor, kMenuEndColor};
    SkShader* s = SkGradientShader::CreateLinear(
        p, colors, NULL, 2, SkShader::kClamp_TileMode, NULL);
    paint.setShader(s);
    // Need to unref shader, otherwise never deleted.
    s->unref();
    canvas->AsCanvasSkia()->drawPath(path, paint);
  }

  virtual void GetInsets(gfx::Insets* insets) const {
    DCHECK(insets);
    menu_locator_->GetInsets(insets);
  }

  chromeos::MenuLocator* menu_locator_;  // not owned

  DISALLOW_COPY_AND_ASSIGN(RoundedBorder);
};

class InsetsLayout : public views::LayoutManager {
 public:
  InsetsLayout() : views::LayoutManager() {}

 private:
  // views::LayoutManager implementatios.
  virtual void Layout(views::View* host) {
    if (host->GetChildViewCount() == 0)
      return;
    gfx::Insets insets = host->GetInsets();
    views::View* view = host->GetChildViewAt(0);

    view->SetBounds(insets.left(), insets.top(),
                    host->width() - insets.width(),
                    host->height() - insets.height());
  }

  virtual gfx::Size GetPreferredSize(views::View* host) {
    DCHECK(host->GetChildViewCount() == 1);
    gfx::Insets insets = host->GetInsets();
    gfx::Size size = host->GetChildViewAt(0)->GetPreferredSize();
    return gfx::Size(size.width() + insets.width(),
                     size.height() + insets.height());
  }

  DISALLOW_COPY_AND_ASSIGN(InsetsLayout);
};

// A gtk widget key used to test if a given WidgetGtk instance is
// DOMUIMenuWidgetKey.
const char* kDOMUIMenuWidgetKey = "__DOMUI_MENU_WIDGET__";

}  // namespace

namespace chromeos {

// static
DOMUIMenuWidget* DOMUIMenuWidget::FindDOMUIMenuWidget(gfx::NativeView native) {
  DCHECK(native);
  native = gtk_widget_get_toplevel(native);
  if (!native)
    return NULL;
  return static_cast<chromeos::DOMUIMenuWidget*>(
      g_object_get_data(G_OBJECT(native), kDOMUIMenuWidgetKey));
}

///////////////////////////////////////////////////////////////////////////////
// DOMUIMenuWidget public:

DOMUIMenuWidget::DOMUIMenuWidget(chromeos::NativeMenuDOMUI* domui_menu,
                                 bool root)
    : views::WidgetGtk(views::WidgetGtk::TYPE_POPUP),
      domui_menu_(domui_menu),
      dom_view_(NULL),
      did_pointer_grab_(false),
      is_root_(root) {
  DCHECK(domui_menu_);
  MakeTransparent();
}

DOMUIMenuWidget::~DOMUIMenuWidget() {
}

void DOMUIMenuWidget::Init(gfx::NativeView parent, const gfx::Rect& bounds) {
  WidgetGtk::Init(parent, bounds);
  gtk_window_set_destroy_with_parent(GTK_WINDOW(GetNativeView()), TRUE);
  gtk_window_set_type_hint(GTK_WINDOW(GetNativeView()),
                           GDK_WINDOW_TYPE_HINT_MENU);
  g_object_set_data(G_OBJECT(GetNativeView()), kDOMUIMenuWidgetKey, this);
}

void DOMUIMenuWidget::Hide() {
  ReleaseGrab();
  WidgetGtk::Hide();
}

void DOMUIMenuWidget::Close() {
  // Detach the domui_menu_ which is being deleted.
  domui_menu_ = NULL;
  views::WidgetGtk::Close();
}

void DOMUIMenuWidget::ReleaseGrab() {
  WidgetGtk::ReleaseGrab();
  if (did_pointer_grab_) {
    did_pointer_grab_ = false;
    gdk_pointer_ungrab(GDK_CURRENT_TIME);

    ClearGrabWidget();
  }
}

gboolean DOMUIMenuWidget::OnGrabBrokeEvent(GtkWidget* widget,
                                           GdkEvent* event) {
  did_pointer_grab_ = false;
  Hide();
  return WidgetGtk::OnGrabBrokeEvent(widget, event);
}

void DOMUIMenuWidget::OnSizeAllocate(GtkWidget* widget,
                                     GtkAllocation* allocation) {
  views::WidgetGtk::OnSizeAllocate(widget, allocation);
  // Adjust location when menu gets resized.
  gfx::Rect bounds;
  GetBounds(&bounds, false);
  // Don't move until the menu gets contents.
  if (bounds.height() >= 2)
    menu_locator_->Move(this);
}

gboolean MapToFocus(GtkWidget* widget, GdkEvent* event, gpointer data) {
  DOMUIMenuWidget* menu_widget = DOMUIMenuWidget::FindDOMUIMenuWidget(widget);
  if (menu_widget)
    menu_widget->EnableInput(false);
  return true;
}

void DOMUIMenuWidget::EnableInput(bool select_item) {
  DCHECK(dom_view_);
  DCHECK(dom_view_->tab_contents()->render_view_host());
  DCHECK(dom_view_->tab_contents()->render_view_host()->view());
  GtkWidget* target =
      dom_view_->tab_contents()->render_view_host()->view()->GetNativeView();
  DCHECK(target);
  // Skip if the widget already own the input.
  if (gtk_grab_get_current() == target)
    return;

  ClearGrabWidget();

  if (!GTK_WIDGET_REALIZED(target)) {
    // Try again if the widget is not yet realized.
    // This happens only for root which tries to open & grab input.
    DCHECK(is_root_);
    DCHECK(!select_item);
    g_signal_connect(G_OBJECT(target), "map-event",
                     G_CALLBACK(&MapToFocus), NULL);
    return;
  }

  gtk_grab_add(target);
  dom_view_->tab_contents()->Focus();
  if (select_item) {
    ExecuteJavascript(L"selectItem()");
  }
}

void DOMUIMenuWidget::ExecuteJavascript(const std::wstring& script) {
  // Don't exeute there is no DOMView associated. This is fine because
  // 1) selectItem make sense only when DOMView is associated.
  // 2) updateModel will be called again when a DOMView is created/assigned.
  if (dom_view_ == NULL)
    return;

  DCHECK(dom_view_->tab_contents()->render_view_host());
  dom_view_->tab_contents()->render_view_host()->
      ExecuteJavascriptInWebFrame(std::wstring(), script);
}

void DOMUIMenuWidget::ShowAt(chromeos::MenuLocator* locator) {
  DCHECK(domui_menu_);
  menu_locator_.reset(locator);
  if (!dom_view_) {
    dom_view_ = new DOMView();
    dom_view_->Init(domui_menu_->GetProfile(), NULL);
    // TODO(oshima): remove extra view to draw rounded corner.
    views::View* container = new views::View();
    container->AddChildView(dom_view_);
    container->set_border(new RoundedBorder(locator));
    container->SetLayoutManager(new InsetsLayout());
    SetContentsView(container);
    dom_view_->LoadURL(GURL("chrome://menu"));
  } else {
    domui_menu_->UpdateStates();
    dom_view_->GetParent()->set_border(new RoundedBorder(locator));
    menu_locator_->Move(this);
  }
  Show();

  // The pointer grab is captured only on the top level menu,
  // all mouse event events are delivered to submenu using gtk_add_grab.
  if (is_root_) {
    CaptureGrab();
  }
}

void DOMUIMenuWidget::SetSize(const gfx::Size& new_size) {
  DCHECK(domui_menu_);
  // Ignore the empty new_size request which is called when
  // menu.html is loaded.
  if (new_size.IsEmpty()) return;

  menu_locator_->SetBounds(this, new_size);
}

///////////////////////////////////////////////////////////////////////////////
// DOMUIMenuWidget private:

void DOMUIMenuWidget::CaptureGrab() {
  // Release the current grab.
  ClearGrabWidget();

  // NOTE: we do this to ensure we get mouse events from other apps, a grab
  // done with gtk_grab_add doesn't get events from other apps.
  GdkGrabStatus grab_status =
      gdk_pointer_grab(window_contents()->window, FALSE,
                       static_cast<GdkEventMask>(
                           GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
                           GDK_POINTER_MOTION_MASK),
                       NULL, NULL, GDK_CURRENT_TIME);
  did_pointer_grab_ = (grab_status == GDK_GRAB_SUCCESS);
  DCHECK(did_pointer_grab_);

  EnableInput(false /* no selection */);
}

void DOMUIMenuWidget::ClearGrabWidget() {
  GtkWidget* grab_widget;
  while ((grab_widget = gtk_grab_get_current()))
    gtk_grab_remove(grab_widget);
}

}   // namespace chromeos
<commit_msg>Fix assertion failure which happens when opening submenu using keyboard navigation quickly.<commit_after>// Copyright (c) 2010 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/chromeos/views/domui_menu_widget.h"

#include "chrome/browser/chromeos/views/menu_locator.h"
#include "chrome/browser/chromeos/views/native_menu_domui.h"
#include "chrome/browser/chromeos/wm_ipc.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_widget_host_view.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/views/dom_view.h"
#include "cros/chromeos_wm_ipc_enums.h"
#include "gfx/canvas_skia.h"
#include "googleurl/src/gurl.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "views/border.h"
#include "views/layout_manager.h"
#include "views/widget/root_view.h"

namespace {

// Colors for menu's graident background.
const SkColor kMenuStartColor = SK_ColorWHITE;
const SkColor kMenuEndColor = 0xFFEEEEEE;

// Rounded border for menu. This draws three types of rounded border,
// for context menu, dropdown menu and submenu. Please see
// menu_locator.cc for details.
class RoundedBorder : public views::Border {
 public:
  explicit RoundedBorder(chromeos::MenuLocator* locator)
      : menu_locator_(locator) {
  }

 private:
  // views::Border implementatios.
  virtual void Paint(const views::View& view, gfx::Canvas* canvas) const {
    const SkScalar* corners = menu_locator_->GetCorners();
    // The menu is in off screen so no need to draw corners.
    if (!corners)
      return;
    int w = view.width();
    int h = view.height();
    SkRect rect = {0, 0, w, h};
    SkPath path;
    path.addRoundRect(rect, corners);
    SkPaint paint;
    paint.setStyle(SkPaint::kFill_Style);
    paint.setFlags(SkPaint::kAntiAlias_Flag);
    SkPoint p[2] = { {0, 0}, {0, h} };
    SkColor colors[2] = {kMenuStartColor, kMenuEndColor};
    SkShader* s = SkGradientShader::CreateLinear(
        p, colors, NULL, 2, SkShader::kClamp_TileMode, NULL);
    paint.setShader(s);
    // Need to unref shader, otherwise never deleted.
    s->unref();
    canvas->AsCanvasSkia()->drawPath(path, paint);
  }

  virtual void GetInsets(gfx::Insets* insets) const {
    DCHECK(insets);
    menu_locator_->GetInsets(insets);
  }

  chromeos::MenuLocator* menu_locator_;  // not owned

  DISALLOW_COPY_AND_ASSIGN(RoundedBorder);
};

class InsetsLayout : public views::LayoutManager {
 public:
  InsetsLayout() : views::LayoutManager() {}

 private:
  // views::LayoutManager implementatios.
  virtual void Layout(views::View* host) {
    if (host->GetChildViewCount() == 0)
      return;
    gfx::Insets insets = host->GetInsets();
    views::View* view = host->GetChildViewAt(0);

    view->SetBounds(insets.left(), insets.top(),
                    host->width() - insets.width(),
                    host->height() - insets.height());
  }

  virtual gfx::Size GetPreferredSize(views::View* host) {
    DCHECK(host->GetChildViewCount() == 1);
    gfx::Insets insets = host->GetInsets();
    gfx::Size size = host->GetChildViewAt(0)->GetPreferredSize();
    return gfx::Size(size.width() + insets.width(),
                     size.height() + insets.height());
  }

  DISALLOW_COPY_AND_ASSIGN(InsetsLayout);
};

// A gtk widget key used to test if a given WidgetGtk instance is
// DOMUIMenuWidgetKey.
const char* kDOMUIMenuWidgetKey = "__DOMUI_MENU_WIDGET__";

}  // namespace

namespace chromeos {

// static
DOMUIMenuWidget* DOMUIMenuWidget::FindDOMUIMenuWidget(gfx::NativeView native) {
  DCHECK(native);
  native = gtk_widget_get_toplevel(native);
  if (!native)
    return NULL;
  return static_cast<chromeos::DOMUIMenuWidget*>(
      g_object_get_data(G_OBJECT(native), kDOMUIMenuWidgetKey));
}

///////////////////////////////////////////////////////////////////////////////
// DOMUIMenuWidget public:

DOMUIMenuWidget::DOMUIMenuWidget(chromeos::NativeMenuDOMUI* domui_menu,
                                 bool root)
    : views::WidgetGtk(views::WidgetGtk::TYPE_POPUP),
      domui_menu_(domui_menu),
      dom_view_(NULL),
      did_pointer_grab_(false),
      is_root_(root) {
  DCHECK(domui_menu_);
  MakeTransparent();
}

DOMUIMenuWidget::~DOMUIMenuWidget() {
}

void DOMUIMenuWidget::Init(gfx::NativeView parent, const gfx::Rect& bounds) {
  WidgetGtk::Init(parent, bounds);
  gtk_window_set_destroy_with_parent(GTK_WINDOW(GetNativeView()), TRUE);
  gtk_window_set_type_hint(GTK_WINDOW(GetNativeView()),
                           GDK_WINDOW_TYPE_HINT_MENU);
  g_object_set_data(G_OBJECT(GetNativeView()), kDOMUIMenuWidgetKey, this);
}

void DOMUIMenuWidget::Hide() {
  ReleaseGrab();
  WidgetGtk::Hide();
}

void DOMUIMenuWidget::Close() {
  // Detach the domui_menu_ which is being deleted.
  domui_menu_ = NULL;
  views::WidgetGtk::Close();
}

void DOMUIMenuWidget::ReleaseGrab() {
  WidgetGtk::ReleaseGrab();
  if (did_pointer_grab_) {
    did_pointer_grab_ = false;
    gdk_pointer_ungrab(GDK_CURRENT_TIME);

    ClearGrabWidget();
  }
}

gboolean DOMUIMenuWidget::OnGrabBrokeEvent(GtkWidget* widget,
                                           GdkEvent* event) {
  did_pointer_grab_ = false;
  Hide();
  return WidgetGtk::OnGrabBrokeEvent(widget, event);
}

void DOMUIMenuWidget::OnSizeAllocate(GtkWidget* widget,
                                     GtkAllocation* allocation) {
  views::WidgetGtk::OnSizeAllocate(widget, allocation);
  // Adjust location when menu gets resized.
  gfx::Rect bounds;
  GetBounds(&bounds, false);
  // Don't move until the menu gets contents.
  if (bounds.height() >= 2)
    menu_locator_->Move(this);
}

gboolean MapToFocus(GtkWidget* widget, GdkEvent* event, gpointer data) {
  DOMUIMenuWidget* menu_widget = DOMUIMenuWidget::FindDOMUIMenuWidget(widget);
  if (menu_widget) {
    // See EnableInput for the meaning of data.
    bool select_item = data != NULL;
    menu_widget->EnableInput(select_item);
  }
  return true;
}

void DOMUIMenuWidget::EnableInput(bool select_item) {
  DCHECK(dom_view_);
  DCHECK(dom_view_->tab_contents()->render_view_host());
  DCHECK(dom_view_->tab_contents()->render_view_host()->view());
  GtkWidget* target =
      dom_view_->tab_contents()->render_view_host()->view()->GetNativeView();
  DCHECK(target);
  // Skip if the widget already own the input.
  if (gtk_grab_get_current() == target)
    return;

  ClearGrabWidget();

  if (!GTK_WIDGET_REALIZED(target)) {
    // Wait grabbing widget if the widget is not yet realized.
    // Using data as a flag. |select_item| is false if data is NULL,
    // or true otherwise.
    g_signal_connect(G_OBJECT(target), "map-event",
                     G_CALLBACK(&MapToFocus),
                     select_item ? this : NULL);
    return;
  }

  gtk_grab_add(target);
  dom_view_->tab_contents()->Focus();
  if (select_item) {
    ExecuteJavascript(L"selectItem()");
  }
}

void DOMUIMenuWidget::ExecuteJavascript(const std::wstring& script) {
  // Don't exeute there is no DOMView associated. This is fine because
  // 1) selectItem make sense only when DOMView is associated.
  // 2) updateModel will be called again when a DOMView is created/assigned.
  if (dom_view_ == NULL)
    return;

  DCHECK(dom_view_->tab_contents()->render_view_host());
  dom_view_->tab_contents()->render_view_host()->
      ExecuteJavascriptInWebFrame(std::wstring(), script);
}

void DOMUIMenuWidget::ShowAt(chromeos::MenuLocator* locator) {
  DCHECK(domui_menu_);
  menu_locator_.reset(locator);
  if (!dom_view_) {
    dom_view_ = new DOMView();
    dom_view_->Init(domui_menu_->GetProfile(), NULL);
    // TODO(oshima): remove extra view to draw rounded corner.
    views::View* container = new views::View();
    container->AddChildView(dom_view_);
    container->set_border(new RoundedBorder(locator));
    container->SetLayoutManager(new InsetsLayout());
    SetContentsView(container);
    dom_view_->LoadURL(GURL("chrome://menu"));
  } else {
    domui_menu_->UpdateStates();
    dom_view_->GetParent()->set_border(new RoundedBorder(locator));
    menu_locator_->Move(this);
  }
  Show();

  // The pointer grab is captured only on the top level menu,
  // all mouse event events are delivered to submenu using gtk_add_grab.
  if (is_root_) {
    CaptureGrab();
  }
}

void DOMUIMenuWidget::SetSize(const gfx::Size& new_size) {
  DCHECK(domui_menu_);
  // Ignore the empty new_size request which is called when
  // menu.html is loaded.
  if (new_size.IsEmpty()) return;

  menu_locator_->SetBounds(this, new_size);
}

///////////////////////////////////////////////////////////////////////////////
// DOMUIMenuWidget private:

void DOMUIMenuWidget::CaptureGrab() {
  // Release the current grab.
  ClearGrabWidget();

  // NOTE: we do this to ensure we get mouse events from other apps, a grab
  // done with gtk_grab_add doesn't get events from other apps.
  GdkGrabStatus grab_status =
      gdk_pointer_grab(window_contents()->window, FALSE,
                       static_cast<GdkEventMask>(
                           GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
                           GDK_POINTER_MOTION_MASK),
                       NULL, NULL, GDK_CURRENT_TIME);
  did_pointer_grab_ = (grab_status == GDK_GRAB_SUCCESS);
  DCHECK(did_pointer_grab_);

  EnableInput(false /* no selection */);
}

void DOMUIMenuWidget::ClearGrabWidget() {
  GtkWidget* grab_widget;
  while ((grab_widget = gtk_grab_get_current()))
    gtk_grab_remove(grab_widget);
}

}   // namespace chromeos
<|endoftext|>


<commit_before>// Copyright (c) 2010 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/chromeos/views/domui_menu_widget.h"

#include "base/stringprintf.h"
#include "chrome/browser/chromeos/views/menu_locator.h"
#include "chrome/browser/chromeos/views/native_menu_domui.h"
#include "chrome/browser/chromeos/wm_ipc.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_widget_host_view.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/views/dom_view.h"
#include "cros/chromeos_wm_ipc_enums.h"
#include "gfx/canvas_skia.h"
#include "googleurl/src/gurl.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "views/border.h"
#include "views/layout_manager.h"
#include "views/widget/root_view.h"

namespace {

// Colors for menu's graident background.
const SkColor kMenuStartColor = SK_ColorWHITE;
const SkColor kMenuEndColor = 0xFFEEEEEE;

// Rounded border for menu. This draws three types of rounded border,
// for context menu, dropdown menu and submenu. Please see
// menu_locator.cc for details.
class RoundedBorder : public views::Border {
 public:
  explicit RoundedBorder(chromeos::MenuLocator* locator)
      : menu_locator_(locator) {
  }

 private:
  // views::Border implementatios.
  virtual void Paint(const views::View& view, gfx::Canvas* canvas) const {
    const SkScalar* corners = menu_locator_->GetCorners();
    // The menu is in off screen so no need to draw corners.
    if (!corners)
      return;
    int w = view.width();
    int h = view.height();
    SkRect rect = {0, 0, w, h};
    SkPath path;
    path.addRoundRect(rect, corners);
    SkPaint paint;
    paint.setStyle(SkPaint::kFill_Style);
    paint.setFlags(SkPaint::kAntiAlias_Flag);
    SkPoint p[2] = { {0, 0}, {0, h} };
    SkColor colors[2] = {kMenuStartColor, kMenuEndColor};
    SkShader* s = SkGradientShader::CreateLinear(
        p, colors, NULL, 2, SkShader::kClamp_TileMode, NULL);
    paint.setShader(s);
    // Need to unref shader, otherwise never deleted.
    s->unref();
    canvas->AsCanvasSkia()->drawPath(path, paint);
  }

  virtual void GetInsets(gfx::Insets* insets) const {
    DCHECK(insets);
    menu_locator_->GetInsets(insets);
  }

  chromeos::MenuLocator* menu_locator_;  // not owned

  DISALLOW_COPY_AND_ASSIGN(RoundedBorder);
};

class InsetsLayout : public views::LayoutManager {
 public:
  InsetsLayout() : views::LayoutManager() {}

 private:
  // views::LayoutManager implementatios.
  virtual void Layout(views::View* host) {
    if (host->GetChildViewCount() == 0)
      return;
    gfx::Insets insets = host->GetInsets();
    views::View* view = host->GetChildViewAt(0);

    view->SetBounds(insets.left(), insets.top(),
                    host->width() - insets.width(),
                    host->height() - insets.height());
  }

  virtual gfx::Size GetPreferredSize(views::View* host) {
    DCHECK(host->GetChildViewCount() == 1);
    gfx::Insets insets = host->GetInsets();
    gfx::Size size = host->GetChildViewAt(0)->GetPreferredSize();
    return gfx::Size(size.width() + insets.width(),
                     size.height() + insets.height());
  }

  DISALLOW_COPY_AND_ASSIGN(InsetsLayout);
};

// A gtk widget key used to test if a given WidgetGtk instance is
// DOMUIMenuWidgetKey.
const char* kDOMUIMenuWidgetKey = "__DOMUI_MENU_WIDGET__";

}  // namespace

namespace chromeos {

// static
DOMUIMenuWidget* DOMUIMenuWidget::FindDOMUIMenuWidget(gfx::NativeView native) {
  DCHECK(native);
  native = gtk_widget_get_toplevel(native);
  if (!native)
    return NULL;
  return static_cast<chromeos::DOMUIMenuWidget*>(
      g_object_get_data(G_OBJECT(native), kDOMUIMenuWidgetKey));
}

///////////////////////////////////////////////////////////////////////////////
// DOMUIMenuWidget public:

DOMUIMenuWidget::DOMUIMenuWidget(chromeos::NativeMenuDOMUI* domui_menu,
                                 bool root)
    : views::WidgetGtk(views::WidgetGtk::TYPE_POPUP),
      domui_menu_(domui_menu),
      dom_view_(NULL),
      did_pointer_grab_(false),
      is_root_(root) {
  DCHECK(domui_menu_);
  // TODO(oshima): Disabling transparent until we migrate bookmark
  // menus to DOMUI.  See crosbug.com/7718.
  // MakeTransparent();
}

DOMUIMenuWidget::~DOMUIMenuWidget() {
}

void DOMUIMenuWidget::Init(gfx::NativeView parent, const gfx::Rect& bounds) {
  WidgetGtk::Init(parent, bounds);
  gtk_window_set_destroy_with_parent(GTK_WINDOW(GetNativeView()), TRUE);
  gtk_window_set_type_hint(GTK_WINDOW(GetNativeView()),
                           GDK_WINDOW_TYPE_HINT_MENU);
  g_object_set_data(G_OBJECT(GetNativeView()), kDOMUIMenuWidgetKey, this);
}

void DOMUIMenuWidget::Hide() {
  ReleaseGrab();
  WidgetGtk::Hide();
}

void DOMUIMenuWidget::Close() {
  // Detach the domui_menu_ which is being deleted.
  domui_menu_ = NULL;
  views::WidgetGtk::Close();
}

void DOMUIMenuWidget::ReleaseGrab() {
  WidgetGtk::ReleaseGrab();
  if (did_pointer_grab_) {
    did_pointer_grab_ = false;
    gdk_pointer_ungrab(GDK_CURRENT_TIME);

    ClearGrabWidget();
  }
}

gboolean DOMUIMenuWidget::OnGrabBrokeEvent(GtkWidget* widget,
                                           GdkEvent* event) {
  did_pointer_grab_ = false;
  Hide();
  return WidgetGtk::OnGrabBrokeEvent(widget, event);
}

void DOMUIMenuWidget::OnSizeAllocate(GtkWidget* widget,
                                     GtkAllocation* allocation) {
  views::WidgetGtk::OnSizeAllocate(widget, allocation);
  // Adjust location when menu gets resized.
  gfx::Rect bounds;
  GetBounds(&bounds, false);
  // Don't move until the menu gets contents.
  if (bounds.height() > 1)
    menu_locator_->Move(this);
}

gboolean MapToFocus(GtkWidget* widget, GdkEvent* event, gpointer data) {
  DOMUIMenuWidget* menu_widget = DOMUIMenuWidget::FindDOMUIMenuWidget(widget);
  if (menu_widget) {
    // See EnableInput for the meaning of data.
    bool select_item = data != NULL;
    menu_widget->EnableInput(select_item);
  }
  return true;
}

void DOMUIMenuWidget::EnableScroll(bool enable) {
  ExecuteJavascript(StringPrintf(
      L"enableScroll(%ls)", enable ? L"true" : L"false" ));
}

void DOMUIMenuWidget::EnableInput(bool select_item) {
  DCHECK(dom_view_);
  DCHECK(dom_view_->tab_contents()->render_view_host());
  DCHECK(dom_view_->tab_contents()->render_view_host()->view());
  GtkWidget* target =
      dom_view_->tab_contents()->render_view_host()->view()->GetNativeView();
  DCHECK(target);
  // Skip if the widget already own the input.
  if (gtk_grab_get_current() == target)
    return;

  ClearGrabWidget();

  if (!GTK_WIDGET_REALIZED(target)) {
    // Wait grabbing widget if the widget is not yet realized.
    // Using data as a flag. |select_item| is false if data is NULL,
    // or true otherwise.
    g_signal_connect(G_OBJECT(target), "map-event",
                     G_CALLBACK(&MapToFocus),
                     select_item ? this : NULL);
    return;
  }

  gtk_grab_add(target);
  dom_view_->tab_contents()->Focus();
  if (select_item) {
    ExecuteJavascript(L"selectItem()");
  }
  domui_menu_->InputIsReady();
}

void DOMUIMenuWidget::ExecuteJavascript(const std::wstring& script) {
  // Don't exeute there is no DOMView associated. This is fine because
  // 1) selectItem make sense only when DOMView is associated.
  // 2) updateModel will be called again when a DOMView is created/assigned.
  if (dom_view_ == NULL)
    return;

  DCHECK(dom_view_->tab_contents()->render_view_host());
  dom_view_->tab_contents()->render_view_host()->
      ExecuteJavascriptInWebFrame(std::wstring(), script);
}

void DOMUIMenuWidget::ShowAt(chromeos::MenuLocator* locator) {
  DCHECK(domui_menu_);
  menu_locator_.reset(locator);
  if (!dom_view_) {
    dom_view_ = new DOMView();
    dom_view_->Init(domui_menu_->GetProfile(), NULL);
    // TODO(oshima): remove extra view to draw rounded corner.
    views::View* container = new views::View();
    container->AddChildView(dom_view_);
    container->set_border(new RoundedBorder(locator));
    container->SetLayoutManager(new InsetsLayout());
    SetContentsView(container);
    dom_view_->LoadURL(domui_menu_->menu_url());
  } else {
    domui_menu_->UpdateStates();
    dom_view_->GetParent()->set_border(new RoundedBorder(locator));
    menu_locator_->Move(this);
  }
  Show();

  // The pointer grab is captured only on the top level menu,
  // all mouse event events are delivered to submenu using gtk_add_grab.
  if (is_root_) {
    CaptureGrab();
  }
}

void DOMUIMenuWidget::SetSize(const gfx::Size& new_size) {
  DCHECK(domui_menu_);
  // Ignore the empty new_size request which is called when
  // menu.html is loaded.
  if (new_size.IsEmpty()) return;

  menu_locator_->SetBounds(this, new_size);
}

///////////////////////////////////////////////////////////////////////////////
// DOMUIMenuWidget private:

void DOMUIMenuWidget::CaptureGrab() {
  // Release the current grab.
  ClearGrabWidget();

  // NOTE: we do this to ensure we get mouse events from other apps, a grab
  // done with gtk_grab_add doesn't get events from other apps.
  GdkGrabStatus grab_status =
      gdk_pointer_grab(window_contents()->window, FALSE,
                       static_cast<GdkEventMask>(
                           GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
                           GDK_POINTER_MOTION_MASK),
                       NULL, NULL, GDK_CURRENT_TIME);
  did_pointer_grab_ = (grab_status == GDK_GRAB_SUCCESS);
  DCHECK(did_pointer_grab_);

  EnableInput(false /* no selection */);
}

void DOMUIMenuWidget::ClearGrabWidget() {
  GtkWidget* grab_widget;
  while ((grab_widget = gtk_grab_get_current()))
    gtk_grab_remove(grab_widget);
}

}   // namespace chromeos
<commit_msg>Warmup DOMView so that the 1st time menu open is fast.  DOMViewCache caches one instance for current profile. It  delets and creates new one if profile is switched.<commit_after>// Copyright (c) 2010 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/chromeos/views/domui_menu_widget.h"

#include "base/stringprintf.h"
#include "base/singleton.h"
#include "base/task.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/chromeos/views/menu_locator.h"
#include "chrome/browser/chromeos/views/native_menu_domui.h"
#include "chrome/browser/chromeos/wm_ipc.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_widget_host_view.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/views/dom_view.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/url_constants.h"
#include "cros/chromeos_wm_ipc_enums.h"
#include "gfx/canvas_skia.h"
#include "googleurl/src/gurl.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "views/border.h"
#include "views/layout_manager.h"
#include "views/widget/root_view.h"

namespace {

// Colors for menu's graident background.
const SkColor kMenuStartColor = SK_ColorWHITE;
const SkColor kMenuEndColor = 0xFFEEEEEE;

// Rounded border for menu. This draws three types of rounded border,
// for context menu, dropdown menu and submenu. Please see
// menu_locator.cc for details.
class RoundedBorder : public views::Border {
 public:
  explicit RoundedBorder(chromeos::MenuLocator* locator)
      : menu_locator_(locator) {
  }

 private:
  // views::Border implementatios.
  virtual void Paint(const views::View& view, gfx::Canvas* canvas) const {
    const SkScalar* corners = menu_locator_->GetCorners();
    // The menu is in off screen so no need to draw corners.
    if (!corners)
      return;
    int w = view.width();
    int h = view.height();
    SkRect rect = {0, 0, w, h};
    SkPath path;
    path.addRoundRect(rect, corners);
    SkPaint paint;
    paint.setStyle(SkPaint::kFill_Style);
    paint.setFlags(SkPaint::kAntiAlias_Flag);
    SkPoint p[2] = { {0, 0}, {0, h} };
    SkColor colors[2] = {kMenuStartColor, kMenuEndColor};
    SkShader* s = SkGradientShader::CreateLinear(
        p, colors, NULL, 2, SkShader::kClamp_TileMode, NULL);
    paint.setShader(s);
    // Need to unref shader, otherwise never deleted.
    s->unref();
    canvas->AsCanvasSkia()->drawPath(path, paint);
  }

  virtual void GetInsets(gfx::Insets* insets) const {
    DCHECK(insets);
    menu_locator_->GetInsets(insets);
  }

  chromeos::MenuLocator* menu_locator_;  // not owned

  DISALLOW_COPY_AND_ASSIGN(RoundedBorder);
};

class InsetsLayout : public views::LayoutManager {
 public:
  InsetsLayout() : views::LayoutManager() {}

 private:
  // views::LayoutManager implementatios.
  virtual void Layout(views::View* host) {
    if (host->GetChildViewCount() == 0)
      return;
    gfx::Insets insets = host->GetInsets();
    views::View* view = host->GetChildViewAt(0);

    view->SetBounds(insets.left(), insets.top(),
                    host->width() - insets.width(),
                    host->height() - insets.height());
  }

  virtual gfx::Size GetPreferredSize(views::View* host) {
    DCHECK(host->GetChildViewCount() == 1);
    gfx::Insets insets = host->GetInsets();
    gfx::Size size = host->GetChildViewAt(0)->GetPreferredSize();
    return gfx::Size(size.width() + insets.width(),
                     size.height() + insets.height());
  }

  DISALLOW_COPY_AND_ASSIGN(InsetsLayout);
};

const int kDOMViewWarmUpDelayMs = 1000 * 5;

// A delayed task to initialize a cache. This is
// create when a profile is switched.
// (incognito, oobe/login has different profile).
class WarmUpTask : public Task {
 public:
  WarmUpTask() {}
  virtual ~WarmUpTask() {}

  virtual void Run();

 private:
  DISALLOW_COPY_AND_ASSIGN(WarmUpTask);
};

// DOMViewCache holds single cache instance of DOMView.
class DOMViewCache : NotificationObserver {
 public:
  DOMViewCache()
      : current_profile_(NULL),
        cache_(NULL) {
    registrar_.Add(this, NotificationType::APP_TERMINATING,
                   NotificationService::AllSources());
  }
  virtual ~DOMViewCache() {}

  // Returns a DOMView for given profile. If there is
  // matching cache,
  DOMView* Get(Profile* profile) {
    if (cache_ &&
        cache_->tab_contents()->profile() == profile) {
      DOMView* c = cache_;
      cache_ = NULL;
      CheckClassInvariant();
      return c;
    }
    DOMView* dom_view = new DOMView();
    dom_view->Init(profile, NULL);
    CheckClassInvariant();
    return dom_view;
  }

  // Release a dom_view. A dom view is reused if its profile matches
  // the current profile, or gets deleted otherwise.
  void Release(DOMView* dom_view) {
    if (cache_ == NULL &&
        current_profile_ == dom_view->tab_contents()->profile()) {
      cache_ = dom_view;
    } else {
      delete dom_view;
    }
    CheckClassInvariant();
  }

  // (Re)Initiailzes the cache with profile.
  // If the current profile does not match the new profile,
  // it delets the existing cache (if any) and creates new one.
  void Init(Profile* profile) {
    if (current_profile_ != profile) {
      delete cache_;
      cache_ = NULL;
      current_profile_ = profile;
      BrowserThread::PostDelayedTask(BrowserThread::UI,
                                     FROM_HERE,
                                     new WarmUpTask(),
                                     kDOMViewWarmUpDelayMs);
    }
    CheckClassInvariant();
  }

  // Create a cache if one does not exist yet.
  void WarmUp() {
    if (cache_) {// domui is created in delay.
      CheckClassInvariant();
      return;
    }
    cache_ = new DOMView();
    cache_->Init(current_profile_, NULL);
    cache_->LoadURL(
        GURL(StringPrintf("chrome://%s", chrome::kChromeUIMenu)));
    CheckClassInvariant();
  }

  // Deletes cached DOMView instance if any.
  void Shutdown() {
    delete cache_;
    cache_ = NULL;
    // Reset current_profile_ as well so that a domview that
    // is currently in use will be deleted in Release as well.
    current_profile_ = NULL;
  }

 private:
  // NotificationObserver impelmentation:
  void Observe(NotificationType type,
               const NotificationSource& source,
               const NotificationDetails& details) {
    DCHECK_EQ(NotificationType::APP_TERMINATING, type.value);
    Shutdown();
  }

  // Tests the class invariant condition.
  void CheckClassInvariant() {
    DCHECK(!cache_ ||
           cache_->tab_contents()->profile() == current_profile_);
  }

  Profile* current_profile_;
  DOMView* cache_;
  NotificationRegistrar registrar_;
};

void WarmUpTask::Run() {
  Singleton<DOMViewCache>::get()->WarmUp();
}

// A gtk widget key used to test if a given WidgetGtk instance is
// DOMUIMenuWidgetKey.
const char* kDOMUIMenuWidgetKey = "__DOMUI_MENU_WIDGET__";

}  // namespace

namespace chromeos {

// static
DOMUIMenuWidget* DOMUIMenuWidget::FindDOMUIMenuWidget(gfx::NativeView native) {
  DCHECK(native);
  native = gtk_widget_get_toplevel(native);
  if (!native)
    return NULL;
  return static_cast<chromeos::DOMUIMenuWidget*>(
      g_object_get_data(G_OBJECT(native), kDOMUIMenuWidgetKey));
}

///////////////////////////////////////////////////////////////////////////////
// DOMUIMenuWidget public:

DOMUIMenuWidget::DOMUIMenuWidget(chromeos::NativeMenuDOMUI* domui_menu,
                                 bool root)
    : views::WidgetGtk(views::WidgetGtk::TYPE_POPUP),
      domui_menu_(domui_menu),
      dom_view_(NULL),
      did_pointer_grab_(false),
      is_root_(root) {
  DCHECK(domui_menu_);
  // TODO(oshima): Disabling transparent until we migrate bookmark
  // menus to DOMUI.  See crosbug.com/7718.
  // MakeTransparent();

  Singleton<DOMViewCache>::get()->Init(domui_menu->GetProfile());
}

DOMUIMenuWidget::~DOMUIMenuWidget() {
}

void DOMUIMenuWidget::Init(gfx::NativeView parent, const gfx::Rect& bounds) {
  WidgetGtk::Init(parent, bounds);
  gtk_window_set_destroy_with_parent(GTK_WINDOW(GetNativeView()), TRUE);
  gtk_window_set_type_hint(GTK_WINDOW(GetNativeView()),
                           GDK_WINDOW_TYPE_HINT_MENU);
  g_object_set_data(G_OBJECT(GetNativeView()), kDOMUIMenuWidgetKey, this);
}

void DOMUIMenuWidget::Hide() {
  ReleaseGrab();
  WidgetGtk::Hide();
}

void DOMUIMenuWidget::Close() {
  if (dom_view_ != NULL) {
    dom_view_->GetParent()->RemoveChildView(dom_view_);
    Singleton<DOMViewCache>::get()->Release(dom_view_);
    dom_view_ = NULL;
  }

  // Detach the domui_menu_ which is being deleted.
  domui_menu_ = NULL;
  views::WidgetGtk::Close();
}

void DOMUIMenuWidget::ReleaseGrab() {
  WidgetGtk::ReleaseGrab();
  if (did_pointer_grab_) {
    did_pointer_grab_ = false;
    gdk_pointer_ungrab(GDK_CURRENT_TIME);

    ClearGrabWidget();
  }
}

gboolean DOMUIMenuWidget::OnGrabBrokeEvent(GtkWidget* widget,
                                           GdkEvent* event) {
  did_pointer_grab_ = false;
  Hide();
  return WidgetGtk::OnGrabBrokeEvent(widget, event);
}

void DOMUIMenuWidget::OnSizeAllocate(GtkWidget* widget,
                                     GtkAllocation* allocation) {
  views::WidgetGtk::OnSizeAllocate(widget, allocation);
  // Adjust location when menu gets resized.
  gfx::Rect bounds;
  GetBounds(&bounds, false);
  // Don't move until the menu gets contents.
  if (bounds.height() > 1)
    menu_locator_->Move(this);
}

gboolean MapToFocus(GtkWidget* widget, GdkEvent* event, gpointer data) {
  DOMUIMenuWidget* menu_widget = DOMUIMenuWidget::FindDOMUIMenuWidget(widget);
  if (menu_widget) {
    // See EnableInput for the meaning of data.
    bool select_item = data != NULL;
    menu_widget->EnableInput(select_item);
  }
  return true;
}

void DOMUIMenuWidget::EnableScroll(bool enable) {
  ExecuteJavascript(StringPrintf(
      L"enableScroll(%ls)", enable ? L"true" : L"false" ));
}

void DOMUIMenuWidget::EnableInput(bool select_item) {
  if (!dom_view_)
    return;
  DCHECK(dom_view_->tab_contents()->render_view_host());
  DCHECK(dom_view_->tab_contents()->render_view_host()->view());
  GtkWidget* target =
      dom_view_->tab_contents()->render_view_host()->view()->GetNativeView();
  DCHECK(target);
  // Skip if the widget already own the input.
  if (gtk_grab_get_current() == target)
    return;

  ClearGrabWidget();

  if (!GTK_WIDGET_REALIZED(target)) {
    // Wait grabbing widget if the widget is not yet realized.
    // Using data as a flag. |select_item| is false if data is NULL,
    // or true otherwise.
    g_signal_connect(G_OBJECT(target), "map-event",
                     G_CALLBACK(&MapToFocus),
                     select_item ? this : NULL);
    return;
  }

  gtk_grab_add(target);
  dom_view_->tab_contents()->Focus();
  if (select_item) {
    ExecuteJavascript(L"selectItem()");
  }
  domui_menu_->InputIsReady();
}

void DOMUIMenuWidget::ExecuteJavascript(const std::wstring& script) {
  // Don't exeute there is no DOMView associated. This is fine because
  // 1) selectItem make sense only when DOMView is associated.
  // 2) updateModel will be called again when a DOMView is created/assigned.
  if (!dom_view_)
    return;

  DCHECK(dom_view_->tab_contents()->render_view_host());
  dom_view_->tab_contents()->render_view_host()->
      ExecuteJavascriptInWebFrame(std::wstring(), script);
}

void DOMUIMenuWidget::ShowAt(chromeos::MenuLocator* locator) {
  DCHECK(domui_menu_);
  menu_locator_.reset(locator);
  if (!dom_view_) {
    dom_view_ = Singleton<DOMViewCache>::get()->Get(domui_menu_->GetProfile());
    dom_view_->Init(domui_menu_->GetProfile(), NULL);
    // TODO(oshima): remove extra view to draw rounded corner.
    views::View* container = new views::View();
    container->AddChildView(dom_view_);
    container->set_border(new RoundedBorder(locator));
    container->SetLayoutManager(new InsetsLayout());
    SetContentsView(container);
    dom_view_->LoadURL(domui_menu_->menu_url());
  } else {
    domui_menu_->UpdateStates();
    dom_view_->GetParent()->set_border(new RoundedBorder(locator));
    menu_locator_->Move(this);
  }
  Show();

  // The pointer grab is captured only on the top level menu,
  // all mouse event events are delivered to submenu using gtk_add_grab.
  if (is_root_) {
    CaptureGrab();
  }
}

void DOMUIMenuWidget::SetSize(const gfx::Size& new_size) {
  DCHECK(domui_menu_);
  // Ignore the empty new_size request which is called when
  // menu.html is loaded.
  if (new_size.IsEmpty()) return;

  menu_locator_->SetBounds(this, new_size);
}

///////////////////////////////////////////////////////////////////////////////
// DOMUIMenuWidget private:

void DOMUIMenuWidget::CaptureGrab() {
  // Release the current grab.
  ClearGrabWidget();

  // NOTE: we do this to ensure we get mouse events from other apps, a grab
  // done with gtk_grab_add doesn't get events from other apps.
  GdkGrabStatus grab_status =
      gdk_pointer_grab(window_contents()->window, FALSE,
                       static_cast<GdkEventMask>(
                           GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
                           GDK_POINTER_MOTION_MASK),
                       NULL, NULL, GDK_CURRENT_TIME);
  did_pointer_grab_ = (grab_status == GDK_GRAB_SUCCESS);
  DCHECK(did_pointer_grab_);

  EnableInput(false /* no selection */);
}

void DOMUIMenuWidget::ClearGrabWidget() {
  GtkWidget* grab_widget;
  while ((grab_widget = gtk_grab_get_current()))
    gtk_grab_remove(grab_widget);
}

}   // namespace chromeos
<|endoftext|>